@diafunc/cli 0.6.0 → 0.8.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/bin/diafunc.js +3 -3
- package/dist/{chunk-CXC5AQC3.js → chunk-B7GDGRAR.js} +2 -2
- package/dist/{chunk-SEX4YGKJ.js → chunk-E4O67FMQ.js} +1978 -692
- package/dist/chunk-E4O67FMQ.js.map +1 -0
- package/dist/{chunk-LXTNUI3L.js → chunk-NSFXPO66.js} +2 -2
- package/dist/{chunk-LXTNUI3L.js.map → chunk-NSFXPO66.js.map} +1 -1
- package/dist/src/index.js +2 -2
- package/dist/update-check-KL3CHODI.js +8 -0
- package/package.json +1 -1
- package/dist/chunk-SEX4YGKJ.js.map +0 -1
- package/dist/update-check-M7H4GTM7.js +0 -8
- /package/dist/{chunk-CXC5AQC3.js.map → chunk-B7GDGRAR.js.map} +0 -0
- /package/dist/{update-check-M7H4GTM7.js.map → update-check-KL3CHODI.js.map} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
package_default
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-NSFXPO66.js";
|
|
4
4
|
|
|
5
5
|
// src/index.ts
|
|
6
6
|
import { Command } from "commander";
|
|
@@ -92,8 +92,8 @@ var NetworkError = class extends Error {
|
|
|
92
92
|
};
|
|
93
93
|
|
|
94
94
|
// src/client/http.ts
|
|
95
|
-
function buildUrl(endpoint, service,
|
|
96
|
-
const base = `${endpoint}/api/v1/${service}${
|
|
95
|
+
function buildUrl(endpoint, service, path11, query) {
|
|
96
|
+
const base = `${endpoint}/api/v1/${service}${path11}`;
|
|
97
97
|
const params = new URLSearchParams();
|
|
98
98
|
if (query) {
|
|
99
99
|
for (const [key, value] of Object.entries(query)) {
|
|
@@ -263,24 +263,6 @@ ${bodyPreview}`);
|
|
|
263
263
|
var SERVICE = "admin";
|
|
264
264
|
function createAdminService(client) {
|
|
265
265
|
return {
|
|
266
|
-
// Sessions
|
|
267
|
-
async createSession(credentials) {
|
|
268
|
-
return client.request({
|
|
269
|
-
method: "POST",
|
|
270
|
-
service: SERVICE,
|
|
271
|
-
path: "/sessions/",
|
|
272
|
-
body: credentials
|
|
273
|
-
});
|
|
274
|
-
},
|
|
275
|
-
async refreshSession(refreshToken) {
|
|
276
|
-
return client.request({
|
|
277
|
-
method: "PUT",
|
|
278
|
-
service: SERVICE,
|
|
279
|
-
path: "/sessions/",
|
|
280
|
-
rawBody: refreshToken,
|
|
281
|
-
contentType: "text/plain"
|
|
282
|
-
});
|
|
283
|
-
},
|
|
284
266
|
// Users
|
|
285
267
|
async getMyUser() {
|
|
286
268
|
return client.request({
|
|
@@ -777,6 +759,7 @@ function registerLogoutCommand(parent) {
|
|
|
777
759
|
method: "POST",
|
|
778
760
|
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
779
761
|
body: new URLSearchParams({
|
|
762
|
+
client_id: profile.auth.clientId,
|
|
780
763
|
token: profile.auth.refreshToken,
|
|
781
764
|
token_type_hint: "refresh_token"
|
|
782
765
|
}).toString()
|
|
@@ -1189,6 +1172,20 @@ function enc(s) {
|
|
|
1189
1172
|
function entityPath(ref) {
|
|
1190
1173
|
return `/${enc(ref.projectId)}/${enc(ref.projectBranch)}/${enc(ref.entityId)}/${enc(ref.entityBranch)}`;
|
|
1191
1174
|
}
|
|
1175
|
+
function exportTableQuery(options) {
|
|
1176
|
+
const query = {};
|
|
1177
|
+
if (options.compression) query.compression = options.compression;
|
|
1178
|
+
if (options.archive) query.archive = options.archive;
|
|
1179
|
+
if (options.fromRow !== void 0 && options.fromRow !== null) query.fromRow = String(options.fromRow);
|
|
1180
|
+
if (options.toRow !== void 0 && options.toRow !== null) query.toRow = String(options.toRow);
|
|
1181
|
+
if (options.fromColumn !== void 0 && options.fromColumn !== null) query.fromColumn = String(options.fromColumn);
|
|
1182
|
+
if (options.toColumn !== void 0 && options.toColumn !== null) query.toColumn = String(options.toColumn);
|
|
1183
|
+
if (options.delimiter !== void 0) query.delimiter = options.delimiter;
|
|
1184
|
+
if (options.quote !== void 0) query.quote = options.quote;
|
|
1185
|
+
if (options.nullValue !== void 0) query.nullValue = options.nullValue;
|
|
1186
|
+
if (options.quoteAll !== void 0) query.quoteAll = String(options.quoteAll);
|
|
1187
|
+
return query;
|
|
1188
|
+
}
|
|
1192
1189
|
function createStorageService(client) {
|
|
1193
1190
|
return {
|
|
1194
1191
|
// --- Entities ---
|
|
@@ -1330,14 +1327,14 @@ function createStorageService(client) {
|
|
|
1330
1327
|
});
|
|
1331
1328
|
},
|
|
1332
1329
|
async deleteLink(projectId, projectBranch, sourceEntityId, sourceEntityBranch, linkId, targetEntityId, targetEntityBranch) {
|
|
1333
|
-
let
|
|
1330
|
+
let path11 = `/links/actual/${enc(projectId)}/${enc(projectBranch)}/${enc(sourceEntityId)}/${enc(sourceEntityBranch)}/${enc(linkId)}`;
|
|
1334
1331
|
if (targetEntityId && targetEntityBranch) {
|
|
1335
|
-
|
|
1332
|
+
path11 += `/${enc(targetEntityId)}/${enc(targetEntityBranch)}`;
|
|
1336
1333
|
}
|
|
1337
1334
|
return client.request({
|
|
1338
1335
|
method: "DELETE",
|
|
1339
1336
|
service: SERVICE3,
|
|
1340
|
-
path:
|
|
1337
|
+
path: path11
|
|
1341
1338
|
});
|
|
1342
1339
|
},
|
|
1343
1340
|
// --- Events ---
|
|
@@ -1394,13 +1391,27 @@ function createStorageService(client) {
|
|
|
1394
1391
|
path: `/tables${entityPath(ref)}/rows`
|
|
1395
1392
|
});
|
|
1396
1393
|
},
|
|
1397
|
-
async
|
|
1394
|
+
async insertRow(ref, rowIndex) {
|
|
1395
|
+
return client.request({
|
|
1396
|
+
method: "POST",
|
|
1397
|
+
service: SERVICE3,
|
|
1398
|
+
path: `/tables${entityPath(ref)}/rows/${rowIndex}/insert`
|
|
1399
|
+
});
|
|
1400
|
+
},
|
|
1401
|
+
async removeRow(ref, rowIndex) {
|
|
1398
1402
|
return client.request({
|
|
1399
1403
|
method: "DELETE",
|
|
1400
1404
|
service: SERVICE3,
|
|
1401
1405
|
path: `/tables${entityPath(ref)}/rows/${rowIndex}`
|
|
1402
1406
|
});
|
|
1403
1407
|
},
|
|
1408
|
+
async deleteRow(ref, rowIndex) {
|
|
1409
|
+
return client.request({
|
|
1410
|
+
method: "POST",
|
|
1411
|
+
service: SERVICE3,
|
|
1412
|
+
path: `/tables${entityPath(ref)}/rows/${rowIndex}/delete`
|
|
1413
|
+
});
|
|
1414
|
+
},
|
|
1404
1415
|
async appendColumn(ref) {
|
|
1405
1416
|
return client.request({
|
|
1406
1417
|
method: "POST",
|
|
@@ -1408,13 +1419,27 @@ function createStorageService(client) {
|
|
|
1408
1419
|
path: `/tables${entityPath(ref)}/columns`
|
|
1409
1420
|
});
|
|
1410
1421
|
},
|
|
1411
|
-
async
|
|
1422
|
+
async insertColumn(ref, columnIndex) {
|
|
1423
|
+
return client.request({
|
|
1424
|
+
method: "POST",
|
|
1425
|
+
service: SERVICE3,
|
|
1426
|
+
path: `/tables${entityPath(ref)}/columns/${columnIndex}/insert`
|
|
1427
|
+
});
|
|
1428
|
+
},
|
|
1429
|
+
async removeColumn(ref, columnIndex) {
|
|
1412
1430
|
return client.request({
|
|
1413
1431
|
method: "DELETE",
|
|
1414
1432
|
service: SERVICE3,
|
|
1415
1433
|
path: `/tables${entityPath(ref)}/columns/${columnIndex}`
|
|
1416
1434
|
});
|
|
1417
1435
|
},
|
|
1436
|
+
async deleteColumn(ref, columnIndex) {
|
|
1437
|
+
return client.request({
|
|
1438
|
+
method: "POST",
|
|
1439
|
+
service: SERVICE3,
|
|
1440
|
+
path: `/tables${entityPath(ref)}/columns/${columnIndex}/delete`
|
|
1441
|
+
});
|
|
1442
|
+
},
|
|
1418
1443
|
async mergeCells(ref, cells) {
|
|
1419
1444
|
return client.request({
|
|
1420
1445
|
method: "PUT",
|
|
@@ -1423,7 +1448,7 @@ function createStorageService(client) {
|
|
|
1423
1448
|
body: cells
|
|
1424
1449
|
});
|
|
1425
1450
|
},
|
|
1426
|
-
async
|
|
1451
|
+
async removeCell(ref, rowIndex, columnIndex) {
|
|
1427
1452
|
return client.request({
|
|
1428
1453
|
method: "DELETE",
|
|
1429
1454
|
service: SERVICE3,
|
|
@@ -1438,15 +1463,24 @@ function createStorageService(client) {
|
|
|
1438
1463
|
});
|
|
1439
1464
|
},
|
|
1440
1465
|
// --- Table Import/Export ---
|
|
1441
|
-
async importTable(ref, formData,
|
|
1466
|
+
async importTable(ref, formData, selection) {
|
|
1467
|
+
const query = {};
|
|
1468
|
+
if (selection) query.selection = selection;
|
|
1442
1469
|
return client.request({
|
|
1443
1470
|
method: "PUT",
|
|
1444
1471
|
service: SERVICE3,
|
|
1445
1472
|
path: `/table-imports${entityPath(ref)}`,
|
|
1446
|
-
query:
|
|
1473
|
+
query: Object.keys(query).length > 0 ? query : void 0,
|
|
1447
1474
|
rawBody: formData
|
|
1448
1475
|
});
|
|
1449
1476
|
},
|
|
1477
|
+
async getSupportedImportFormats() {
|
|
1478
|
+
return client.request({
|
|
1479
|
+
method: "GET",
|
|
1480
|
+
service: SERVICE3,
|
|
1481
|
+
path: `/table-imports/supported-formats`
|
|
1482
|
+
});
|
|
1483
|
+
},
|
|
1450
1484
|
async getImport(ref, importId) {
|
|
1451
1485
|
return client.request({
|
|
1452
1486
|
method: "GET",
|
|
@@ -1454,18 +1488,47 @@ function createStorageService(client) {
|
|
|
1454
1488
|
path: `/imports${entityPath(ref)}/${enc(importId)}`
|
|
1455
1489
|
});
|
|
1456
1490
|
},
|
|
1457
|
-
|
|
1491
|
+
/**
|
|
1492
|
+
* Async (queue) export. Server returns the exportId as plain text; the
|
|
1493
|
+
* caller polls progress via {@code getExport} / {@code listExports}.
|
|
1494
|
+
* For streaming bytes back synchronously, use {@link streamExport}.
|
|
1495
|
+
*/
|
|
1496
|
+
async exportTable(ref, format2, options = {}) {
|
|
1497
|
+
const query = exportTableQuery(options);
|
|
1498
|
+
return client.request({
|
|
1499
|
+
method: "POST",
|
|
1500
|
+
service: SERVICE3,
|
|
1501
|
+
path: `/table-exports${entityPath(ref)}/${enc(format2)}`,
|
|
1502
|
+
query: Object.keys(query).length > 0 ? query : void 0
|
|
1503
|
+
});
|
|
1504
|
+
},
|
|
1505
|
+
/**
|
|
1506
|
+
* Streaming download via the synchronous {@code /stream} endpoint.
|
|
1507
|
+
* Server runs the exporter and writes chunk-encoded bytes back; the CLI
|
|
1508
|
+
* pipes them straight to a file (no async {@code ExportRow}, no progress
|
|
1509
|
+
* polling). Default for {@code diafunc table export} unless {@code
|
|
1510
|
+
* --async} is passed.
|
|
1511
|
+
*/
|
|
1512
|
+
async streamExport(ref, format2, options = {}) {
|
|
1513
|
+
const query = exportTableQuery(options);
|
|
1458
1514
|
return client.requestRaw({
|
|
1459
1515
|
method: "POST",
|
|
1460
1516
|
service: SERVICE3,
|
|
1461
|
-
path: `/table-exports${entityPath(ref)}/
|
|
1517
|
+
path: `/table-exports${entityPath(ref)}/${enc(format2)}/stream`,
|
|
1518
|
+
query: Object.keys(query).length > 0 ? query : void 0
|
|
1462
1519
|
});
|
|
1463
1520
|
},
|
|
1521
|
+
async exportTableCsv(ref) {
|
|
1522
|
+
return this.exportTable(ref, "csv");
|
|
1523
|
+
},
|
|
1464
1524
|
async exportTableExcel(ref) {
|
|
1465
|
-
return
|
|
1466
|
-
|
|
1525
|
+
return this.exportTable(ref, "excel");
|
|
1526
|
+
},
|
|
1527
|
+
async getSupportedExportFormats() {
|
|
1528
|
+
return client.request({
|
|
1529
|
+
method: "GET",
|
|
1467
1530
|
service: SERVICE3,
|
|
1468
|
-
path: `/table-exports
|
|
1531
|
+
path: `/table-exports/supported-formats`
|
|
1469
1532
|
});
|
|
1470
1533
|
},
|
|
1471
1534
|
// --- Branches ---
|
|
@@ -1576,9 +1639,233 @@ function createStorageService(client) {
|
|
|
1576
1639
|
path: "/backups/full/restore",
|
|
1577
1640
|
body: request
|
|
1578
1641
|
});
|
|
1579
|
-
}
|
|
1642
|
+
},
|
|
1580
1643
|
// --- Event write ops (moved from read-only block) ---
|
|
1581
1644
|
// NOTE: createEvents / consumeEvents already exist above in the Events section.
|
|
1645
|
+
// --- User-defined exporters (UDE) ---
|
|
1646
|
+
async listUserDefinedExporters() {
|
|
1647
|
+
return client.request({
|
|
1648
|
+
method: "GET",
|
|
1649
|
+
service: SERVICE3,
|
|
1650
|
+
path: `/table-exporters`
|
|
1651
|
+
});
|
|
1652
|
+
},
|
|
1653
|
+
async registerUserDefinedExporter(request) {
|
|
1654
|
+
return client.request({
|
|
1655
|
+
method: "POST",
|
|
1656
|
+
service: SERVICE3,
|
|
1657
|
+
path: `/table-exporters`,
|
|
1658
|
+
body: request
|
|
1659
|
+
});
|
|
1660
|
+
},
|
|
1661
|
+
async deleteUserDefinedExporter(id) {
|
|
1662
|
+
await client.request({
|
|
1663
|
+
method: "DELETE",
|
|
1664
|
+
service: SERVICE3,
|
|
1665
|
+
path: `/table-exporters/${enc(id)}`
|
|
1666
|
+
});
|
|
1667
|
+
},
|
|
1668
|
+
// --- Data sources ---
|
|
1669
|
+
async createDataSource(request) {
|
|
1670
|
+
return client.request({
|
|
1671
|
+
method: "POST",
|
|
1672
|
+
service: SERVICE3,
|
|
1673
|
+
path: `/data-sources`,
|
|
1674
|
+
body: request
|
|
1675
|
+
});
|
|
1676
|
+
},
|
|
1677
|
+
async listDataSources(projectId) {
|
|
1678
|
+
return client.request({
|
|
1679
|
+
method: "GET",
|
|
1680
|
+
service: SERVICE3,
|
|
1681
|
+
path: `/data-sources`,
|
|
1682
|
+
query: projectId ? { projectId } : void 0
|
|
1683
|
+
});
|
|
1684
|
+
},
|
|
1685
|
+
async getDataSourceDashboard(projectId) {
|
|
1686
|
+
return client.request({
|
|
1687
|
+
method: "GET",
|
|
1688
|
+
service: SERVICE3,
|
|
1689
|
+
path: `/data-sources/dashboard`,
|
|
1690
|
+
query: { projectId }
|
|
1691
|
+
});
|
|
1692
|
+
},
|
|
1693
|
+
async getDataSource(id) {
|
|
1694
|
+
return client.request({
|
|
1695
|
+
method: "GET",
|
|
1696
|
+
service: SERVICE3,
|
|
1697
|
+
path: `/data-sources/${enc(id)}`
|
|
1698
|
+
});
|
|
1699
|
+
},
|
|
1700
|
+
async updateDataSource(id, request) {
|
|
1701
|
+
return client.request({
|
|
1702
|
+
method: "PUT",
|
|
1703
|
+
service: SERVICE3,
|
|
1704
|
+
path: `/data-sources/${enc(id)}`,
|
|
1705
|
+
body: request
|
|
1706
|
+
});
|
|
1707
|
+
},
|
|
1708
|
+
async deleteDataSource(id) {
|
|
1709
|
+
await client.request({
|
|
1710
|
+
method: "DELETE",
|
|
1711
|
+
service: SERVICE3,
|
|
1712
|
+
path: `/data-sources/${enc(id)}`
|
|
1713
|
+
});
|
|
1714
|
+
},
|
|
1715
|
+
async refreshDataSource(id) {
|
|
1716
|
+
return client.request({
|
|
1717
|
+
method: "POST",
|
|
1718
|
+
service: SERVICE3,
|
|
1719
|
+
path: `/data-sources/${enc(id)}/refresh`
|
|
1720
|
+
});
|
|
1721
|
+
},
|
|
1722
|
+
async listDataSourceRuns(id, limit) {
|
|
1723
|
+
return client.request({
|
|
1724
|
+
method: "GET",
|
|
1725
|
+
service: SERVICE3,
|
|
1726
|
+
path: `/data-sources/${enc(id)}/runs`,
|
|
1727
|
+
query: limit !== void 0 ? { limit } : void 0
|
|
1728
|
+
});
|
|
1729
|
+
},
|
|
1730
|
+
async getDataSourceRun(id, runId) {
|
|
1731
|
+
return client.request({
|
|
1732
|
+
method: "GET",
|
|
1733
|
+
service: SERVICE3,
|
|
1734
|
+
path: `/data-sources/${enc(id)}/runs/${enc(runId)}`
|
|
1735
|
+
});
|
|
1736
|
+
},
|
|
1737
|
+
async listDataSourceConnectorTypes() {
|
|
1738
|
+
return client.request({
|
|
1739
|
+
method: "GET",
|
|
1740
|
+
service: SERVICE3,
|
|
1741
|
+
path: `/data-sources/types`
|
|
1742
|
+
});
|
|
1743
|
+
},
|
|
1744
|
+
// --- Skeletons ---
|
|
1745
|
+
async createSkeleton(request) {
|
|
1746
|
+
return client.request({
|
|
1747
|
+
method: "POST",
|
|
1748
|
+
service: SERVICE3,
|
|
1749
|
+
path: `/skeletons`,
|
|
1750
|
+
body: request
|
|
1751
|
+
});
|
|
1752
|
+
},
|
|
1753
|
+
async listSkeletons(projectId) {
|
|
1754
|
+
return client.request({
|
|
1755
|
+
method: "GET",
|
|
1756
|
+
service: SERVICE3,
|
|
1757
|
+
path: `/skeletons`,
|
|
1758
|
+
query: { projectId }
|
|
1759
|
+
});
|
|
1760
|
+
},
|
|
1761
|
+
async getSkeleton(id) {
|
|
1762
|
+
return client.request({
|
|
1763
|
+
method: "GET",
|
|
1764
|
+
service: SERVICE3,
|
|
1765
|
+
path: `/skeletons/${enc(id)}`
|
|
1766
|
+
});
|
|
1767
|
+
},
|
|
1768
|
+
async updateSkeleton(id, request) {
|
|
1769
|
+
return client.request({
|
|
1770
|
+
method: "PUT",
|
|
1771
|
+
service: SERVICE3,
|
|
1772
|
+
path: `/skeletons/${enc(id)}`,
|
|
1773
|
+
body: request
|
|
1774
|
+
});
|
|
1775
|
+
},
|
|
1776
|
+
async deleteSkeleton(id) {
|
|
1777
|
+
await client.request({
|
|
1778
|
+
method: "DELETE",
|
|
1779
|
+
service: SERVICE3,
|
|
1780
|
+
path: `/skeletons/${enc(id)}`
|
|
1781
|
+
});
|
|
1782
|
+
},
|
|
1783
|
+
// --- Notebook bundles ---
|
|
1784
|
+
/** Queue an async bundle export; returns the bundleId for polling. */
|
|
1785
|
+
async exportBundle(projectId, projectBranch, request) {
|
|
1786
|
+
return client.request({
|
|
1787
|
+
method: "POST",
|
|
1788
|
+
service: SERVICE3,
|
|
1789
|
+
path: `/notebook-bundles/${enc(projectId)}/${enc(projectBranch)}/export`,
|
|
1790
|
+
body: request
|
|
1791
|
+
});
|
|
1792
|
+
},
|
|
1793
|
+
/** Streaming download via the synchronous /stream endpoint; pipe bytes to disk. */
|
|
1794
|
+
async streamBundle(projectId, projectBranch, request) {
|
|
1795
|
+
return client.requestRaw({
|
|
1796
|
+
method: "POST",
|
|
1797
|
+
service: SERVICE3,
|
|
1798
|
+
path: `/notebook-bundles/${enc(projectId)}/${enc(projectBranch)}/export/stream`,
|
|
1799
|
+
body: request
|
|
1800
|
+
});
|
|
1801
|
+
},
|
|
1802
|
+
/** Queue an async whole-project (.dfproj) export (async-only; poll + download the result). */
|
|
1803
|
+
async exportProjectBundle(projectId, projectBranch) {
|
|
1804
|
+
return client.request({
|
|
1805
|
+
method: "POST",
|
|
1806
|
+
service: SERVICE3,
|
|
1807
|
+
path: `/project-bundles/${enc(projectId)}/${enc(projectBranch)}/export`
|
|
1808
|
+
});
|
|
1809
|
+
},
|
|
1810
|
+
/** Queue an async entity-subset (.dfset) export; returns the bundleId for polling. */
|
|
1811
|
+
async exportEntitySubset(projectId, projectBranch, request) {
|
|
1812
|
+
return client.request({
|
|
1813
|
+
method: "POST",
|
|
1814
|
+
service: SERVICE3,
|
|
1815
|
+
path: `/entity-subset-bundles/${enc(projectId)}/${enc(projectBranch)}/export`,
|
|
1816
|
+
body: request
|
|
1817
|
+
});
|
|
1818
|
+
},
|
|
1819
|
+
/** Streaming download of an entity-subset bundle via the synchronous /stream endpoint. */
|
|
1820
|
+
async streamEntitySubset(projectId, projectBranch, request) {
|
|
1821
|
+
return client.requestRaw({
|
|
1822
|
+
method: "POST",
|
|
1823
|
+
service: SERVICE3,
|
|
1824
|
+
path: `/entity-subset-bundles/${enc(projectId)}/${enc(projectBranch)}/export/stream`,
|
|
1825
|
+
body: request
|
|
1826
|
+
});
|
|
1827
|
+
},
|
|
1828
|
+
async getBundles(projectId, projectBranch) {
|
|
1829
|
+
return client.request({
|
|
1830
|
+
method: "GET",
|
|
1831
|
+
service: SERVICE3,
|
|
1832
|
+
path: `/bundles/${enc(projectId)}/${enc(projectBranch)}`
|
|
1833
|
+
});
|
|
1834
|
+
},
|
|
1835
|
+
/** Download a finished bundle's bytes. */
|
|
1836
|
+
async getBundleContent(projectId, projectBranch, bundleId, filename) {
|
|
1837
|
+
return client.requestRaw({
|
|
1838
|
+
method: "GET",
|
|
1839
|
+
service: SERVICE3,
|
|
1840
|
+
path: `/bundles/${enc(projectId)}/${enc(projectBranch)}/${enc(bundleId)}/${enc(filename)}`
|
|
1841
|
+
});
|
|
1842
|
+
},
|
|
1843
|
+
async stopBundle(projectId, projectBranch, bundleId, filename) {
|
|
1844
|
+
await client.request({
|
|
1845
|
+
method: "DELETE",
|
|
1846
|
+
service: SERVICE3,
|
|
1847
|
+
path: `/bundles/${enc(projectId)}/${enc(projectBranch)}/${enc(bundleId)}/${enc(filename)}`
|
|
1848
|
+
});
|
|
1849
|
+
},
|
|
1850
|
+
/** Non-committing inventory of an uploaded bundle. */
|
|
1851
|
+
async previewBundleImport(projectId, projectBranch, formData) {
|
|
1852
|
+
return client.request({
|
|
1853
|
+
method: "POST",
|
|
1854
|
+
service: SERVICE3,
|
|
1855
|
+
path: `/notebook-bundle-imports/${enc(projectId)}/${enc(projectBranch)}/preview`,
|
|
1856
|
+
rawBody: formData
|
|
1857
|
+
});
|
|
1858
|
+
},
|
|
1859
|
+
/** Commit an uploaded bundle into the target project. */
|
|
1860
|
+
async importBundle(projectId, projectBranch, formData, onConflict = "copy") {
|
|
1861
|
+
return client.request({
|
|
1862
|
+
method: "POST",
|
|
1863
|
+
service: SERVICE3,
|
|
1864
|
+
path: `/notebook-bundle-imports/${enc(projectId)}/${enc(projectBranch)}/import`,
|
|
1865
|
+
query: { onConflict },
|
|
1866
|
+
rawBody: formData
|
|
1867
|
+
});
|
|
1868
|
+
}
|
|
1582
1869
|
};
|
|
1583
1870
|
}
|
|
1584
1871
|
|
|
@@ -2026,8 +2313,8 @@ function registerConfigCommands(program) {
|
|
|
2026
2313
|
console.log(chalk7.green(`Profile "${name}" removed.`));
|
|
2027
2314
|
});
|
|
2028
2315
|
}
|
|
2029
|
-
function setNestedValue(obj,
|
|
2030
|
-
const keys =
|
|
2316
|
+
function setNestedValue(obj, path11, value) {
|
|
2317
|
+
const keys = path11.split(".");
|
|
2031
2318
|
let current = obj;
|
|
2032
2319
|
for (let i = 0; i < keys.length - 1; i++) {
|
|
2033
2320
|
const key = keys[i];
|
|
@@ -2038,8 +2325,8 @@ function setNestedValue(obj, path9, value) {
|
|
|
2038
2325
|
}
|
|
2039
2326
|
current[keys[keys.length - 1]] = value;
|
|
2040
2327
|
}
|
|
2041
|
-
function getNestedValue(obj,
|
|
2042
|
-
const keys =
|
|
2328
|
+
function getNestedValue(obj, path11) {
|
|
2329
|
+
const keys = path11.split(".");
|
|
2043
2330
|
let current = obj;
|
|
2044
2331
|
for (const key of keys) {
|
|
2045
2332
|
if (current === null || current === void 0 || typeof current !== "object") {
|
|
@@ -2051,38 +2338,222 @@ function getNestedValue(obj, path9) {
|
|
|
2051
2338
|
}
|
|
2052
2339
|
|
|
2053
2340
|
// src/commands/project/index.ts
|
|
2054
|
-
import
|
|
2055
|
-
|
|
2341
|
+
import chalk9 from "chalk";
|
|
2342
|
+
|
|
2343
|
+
// src/util/references.ts
|
|
2344
|
+
function parseEntityReference(ref, overrides) {
|
|
2056
2345
|
const config = loadConfig();
|
|
2057
|
-
const
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
try {
|
|
2064
|
-
const outputFormat = getOutputFormat(cmd);
|
|
2065
|
-
const api = createApiClient();
|
|
2066
|
-
const projects = options.all ? await api.admin.getAllProjects() : await api.admin.getProjects();
|
|
2067
|
-
format(projects, {
|
|
2068
|
-
format: outputFormat,
|
|
2069
|
-
columns: ["projectId", "groupId", "visibility", "language", "active", "locked"]
|
|
2070
|
-
});
|
|
2071
|
-
} catch (error) {
|
|
2072
|
-
handleError(error);
|
|
2346
|
+
const defaultProject = overrides?.project ?? config.defaults.project;
|
|
2347
|
+
const defaultBranch = overrides?.branch ?? config.defaults.branch ?? "main";
|
|
2348
|
+
if (!ref.includes("/") && ref.includes(":")) {
|
|
2349
|
+
const [entityId, entityBranch] = ref.split(":");
|
|
2350
|
+
if (!defaultProject) {
|
|
2351
|
+
throw new Error("No default project configured. Set one with: diafunc config set defaults.project <id>");
|
|
2073
2352
|
}
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2353
|
+
return {
|
|
2354
|
+
projectId: defaultProject,
|
|
2355
|
+
projectBranch: defaultBranch,
|
|
2356
|
+
entityId,
|
|
2357
|
+
entityBranch: entityBranch || defaultBranch
|
|
2358
|
+
};
|
|
2359
|
+
}
|
|
2360
|
+
const parts = ref.split("/");
|
|
2361
|
+
if (parts.length === 1) {
|
|
2362
|
+
if (!defaultProject) {
|
|
2363
|
+
throw new Error("No default project configured. Set one with: diafunc config set defaults.project <id>");
|
|
2083
2364
|
}
|
|
2084
|
-
|
|
2085
|
-
|
|
2365
|
+
return {
|
|
2366
|
+
projectId: defaultProject,
|
|
2367
|
+
projectBranch: defaultBranch,
|
|
2368
|
+
entityId: parts[0],
|
|
2369
|
+
entityBranch: defaultBranch
|
|
2370
|
+
};
|
|
2371
|
+
}
|
|
2372
|
+
if (parts.length === 2) {
|
|
2373
|
+
return {
|
|
2374
|
+
projectId: parts[0],
|
|
2375
|
+
projectBranch: defaultBranch,
|
|
2376
|
+
entityId: parts[1],
|
|
2377
|
+
entityBranch: defaultBranch
|
|
2378
|
+
};
|
|
2379
|
+
}
|
|
2380
|
+
if (parts.length === 3) {
|
|
2381
|
+
if (parts[1] === "") {
|
|
2382
|
+
return {
|
|
2383
|
+
projectId: parts[0],
|
|
2384
|
+
projectBranch: defaultBranch,
|
|
2385
|
+
entityId: parts[2],
|
|
2386
|
+
entityBranch: defaultBranch
|
|
2387
|
+
};
|
|
2388
|
+
}
|
|
2389
|
+
return {
|
|
2390
|
+
projectId: parts[0],
|
|
2391
|
+
projectBranch: parts[1],
|
|
2392
|
+
entityId: parts[2],
|
|
2393
|
+
entityBranch: defaultBranch
|
|
2394
|
+
};
|
|
2395
|
+
}
|
|
2396
|
+
if (parts.length === 4) {
|
|
2397
|
+
return {
|
|
2398
|
+
projectId: parts[0],
|
|
2399
|
+
projectBranch: parts[1] || defaultBranch,
|
|
2400
|
+
entityId: parts[2],
|
|
2401
|
+
entityBranch: parts[3] || defaultBranch
|
|
2402
|
+
};
|
|
2403
|
+
}
|
|
2404
|
+
throw new Error(
|
|
2405
|
+
`Invalid entity reference: "${ref}". Expected format: entityId, entityId:branch, or projectId/projectBranch/entityId/entityBranch`
|
|
2406
|
+
);
|
|
2407
|
+
}
|
|
2408
|
+
function parseProjectReference(ref, overrides) {
|
|
2409
|
+
const config = loadConfig();
|
|
2410
|
+
const defaultProject = overrides?.project ?? config.defaults.project;
|
|
2411
|
+
const defaultBranch = overrides?.branch ?? config.defaults.branch ?? "main";
|
|
2412
|
+
if (!ref.includes("/")) {
|
|
2413
|
+
return {
|
|
2414
|
+
projectId: ref || defaultProject,
|
|
2415
|
+
projectBranch: defaultBranch
|
|
2416
|
+
};
|
|
2417
|
+
}
|
|
2418
|
+
const parts = ref.split("/");
|
|
2419
|
+
return {
|
|
2420
|
+
projectId: parts[0],
|
|
2421
|
+
projectBranch: parts[1] || defaultBranch
|
|
2422
|
+
};
|
|
2423
|
+
}
|
|
2424
|
+
|
|
2425
|
+
// src/commands/bundle-helpers.ts
|
|
2426
|
+
import chalk8 from "chalk";
|
|
2427
|
+
import * as fs2 from "fs";
|
|
2428
|
+
import * as path2 from "path";
|
|
2429
|
+
async function streamResponseToFile(response, outFile) {
|
|
2430
|
+
const buffer = Buffer.from(await response.arrayBuffer());
|
|
2431
|
+
fs2.writeFileSync(outFile, buffer);
|
|
2432
|
+
return buffer.length;
|
|
2433
|
+
}
|
|
2434
|
+
function printLossiness(notes) {
|
|
2435
|
+
if (notes && notes.length > 0) {
|
|
2436
|
+
console.log(chalk8.yellow("Lossiness:"));
|
|
2437
|
+
for (const note of notes) {
|
|
2438
|
+
console.log(chalk8.yellow(` - ${note}`));
|
|
2439
|
+
}
|
|
2440
|
+
}
|
|
2441
|
+
}
|
|
2442
|
+
function printImportPreview(preview) {
|
|
2443
|
+
console.log(chalk8.bold(`${preview.kind} bundle \xB7 ${preview.entityCount} entities`));
|
|
2444
|
+
if (preview.projectName) {
|
|
2445
|
+
console.log(chalk8.dim(preview.projectName));
|
|
2446
|
+
}
|
|
2447
|
+
if (preview.sourceProjectId) {
|
|
2448
|
+
console.log(chalk8.dim(`from ${preview.sourceProjectId}/${preview.sourceProjectBranch}` + (preview.createdBy ? ` \xB7 by ${preview.createdBy}` : "")));
|
|
2449
|
+
}
|
|
2450
|
+
const counts = /* @__PURE__ */ new Map();
|
|
2451
|
+
for (const e of preview.entities ?? []) {
|
|
2452
|
+
counts.set(e.type, (counts.get(e.type) ?? 0) + 1);
|
|
2453
|
+
}
|
|
2454
|
+
for (const [type, count] of [...counts.entries()].sort((a, b) => a[0].localeCompare(b[0]))) {
|
|
2455
|
+
console.log(` ${type}: ${count}`);
|
|
2456
|
+
}
|
|
2457
|
+
if (preview.hasAnalysis) {
|
|
2458
|
+
console.log(" analysis recipe: included");
|
|
2459
|
+
}
|
|
2460
|
+
if (preview.skeletonCount) {
|
|
2461
|
+
console.log(` skeletons: ${preview.skeletonCount}`);
|
|
2462
|
+
}
|
|
2463
|
+
if (preview.redactedDataSourceCount) {
|
|
2464
|
+
console.log(` data sources: ${preview.redactedDataSourceCount} (credentials redacted)`);
|
|
2465
|
+
}
|
|
2466
|
+
printLossiness(preview.lossinessNotes);
|
|
2467
|
+
}
|
|
2468
|
+
function printImportResult(result) {
|
|
2469
|
+
console.log(chalk8.green(`Imported ${result.entityCount} entities, ${result.linkCount} links.`));
|
|
2470
|
+
if (result.skeletonCount) {
|
|
2471
|
+
console.log(`Skeletons: ${result.skeletonCount}`);
|
|
2472
|
+
}
|
|
2473
|
+
if (result.dataSourceCount) {
|
|
2474
|
+
console.log(`Data sources: ${result.dataSourceCount} (re-authenticate before refreshing)`);
|
|
2475
|
+
}
|
|
2476
|
+
if (result.analysisOutcome && result.analysisOutcome !== "none") {
|
|
2477
|
+
console.log(`Analysis recipe: ${result.analysisOutcome}`);
|
|
2478
|
+
}
|
|
2479
|
+
if (result.rootEntityIds.length > 0) {
|
|
2480
|
+
console.log(`Root id(s): ${result.rootEntityIds.join(", ")}`);
|
|
2481
|
+
}
|
|
2482
|
+
printLossiness(result.lossinessNotes);
|
|
2483
|
+
}
|
|
2484
|
+
async function runBundleImport(storage, projectId, projectBranch, file, options, outputFormat) {
|
|
2485
|
+
const fileBuffer = fs2.readFileSync(file);
|
|
2486
|
+
const blob = new Blob([fileBuffer]);
|
|
2487
|
+
const formData = new FormData();
|
|
2488
|
+
formData.append("content", blob, path2.basename(file));
|
|
2489
|
+
if (options.preview) {
|
|
2490
|
+
const preview = await storage.previewBundleImport(projectId, projectBranch, formData);
|
|
2491
|
+
if (outputFormat === "json") {
|
|
2492
|
+
format(preview, { format: outputFormat });
|
|
2493
|
+
return;
|
|
2494
|
+
}
|
|
2495
|
+
printImportPreview(preview);
|
|
2496
|
+
return;
|
|
2497
|
+
}
|
|
2498
|
+
const result = await storage.importBundle(projectId, projectBranch, formData, options.onConflict);
|
|
2499
|
+
if (outputFormat === "json") {
|
|
2500
|
+
format(result, { format: outputFormat });
|
|
2501
|
+
return;
|
|
2502
|
+
}
|
|
2503
|
+
printImportResult(result);
|
|
2504
|
+
}
|
|
2505
|
+
var sleep2 = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
2506
|
+
async function pollUntilFinished(storage, projectId, projectBranch, bundleId, intervalMs = 2e3, maxAttempts = 150) {
|
|
2507
|
+
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
2508
|
+
const bundles = await storage.getBundles(projectId, projectBranch);
|
|
2509
|
+
const job = bundles.find((b) => b.bundleId === bundleId);
|
|
2510
|
+
if (job && job.finished) {
|
|
2511
|
+
if (job.succeeded === false) {
|
|
2512
|
+
throw new Error(`Export failed: ${job.error || "unknown error"}`);
|
|
2513
|
+
}
|
|
2514
|
+
return job;
|
|
2515
|
+
}
|
|
2516
|
+
await sleep2(intervalMs);
|
|
2517
|
+
}
|
|
2518
|
+
throw new Error(`Export ${bundleId} did not finish within the timeout \u2014 poll it with 'diafunc notebook bundles'`);
|
|
2519
|
+
}
|
|
2520
|
+
|
|
2521
|
+
// src/commands/project/index.ts
|
|
2522
|
+
function getOutputFormat(cmd) {
|
|
2523
|
+
const config = loadConfig();
|
|
2524
|
+
const globalOpts = cmd.optsWithGlobals();
|
|
2525
|
+
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
2526
|
+
}
|
|
2527
|
+
function getOverrides(cmd) {
|
|
2528
|
+
const opts = cmd.optsWithGlobals();
|
|
2529
|
+
return { project: opts.project, branch: opts.branch };
|
|
2530
|
+
}
|
|
2531
|
+
function registerProjectCommands(program) {
|
|
2532
|
+
const project = program.command("project").description("Manage projects");
|
|
2533
|
+
project.command("list").description("List projects").option("--all", "List all projects (admin)").action(async (options, cmd) => {
|
|
2534
|
+
try {
|
|
2535
|
+
const outputFormat = getOutputFormat(cmd);
|
|
2536
|
+
const api = createApiClient();
|
|
2537
|
+
const projects = options.all ? await api.admin.getAllProjects() : await api.admin.getProjects();
|
|
2538
|
+
format(projects, {
|
|
2539
|
+
format: outputFormat,
|
|
2540
|
+
columns: ["projectId", "groupId", "visibility", "language", "active", "locked"]
|
|
2541
|
+
});
|
|
2542
|
+
} catch (error) {
|
|
2543
|
+
handleError(error);
|
|
2544
|
+
}
|
|
2545
|
+
});
|
|
2546
|
+
project.command("get").description("Get project details").argument("<projectId>", "Project ID").action(async (projectId, _options, cmd) => {
|
|
2547
|
+
try {
|
|
2548
|
+
const outputFormat = getOutputFormat(cmd);
|
|
2549
|
+
const api = createApiClient();
|
|
2550
|
+
const p = await api.admin.getProject(projectId);
|
|
2551
|
+
format(p, { format: outputFormat });
|
|
2552
|
+
} catch (error) {
|
|
2553
|
+
handleError(error);
|
|
2554
|
+
}
|
|
2555
|
+
});
|
|
2556
|
+
project.command("create").description("Create a new project").option("--visibility <visibility>", "Project visibility (PRIVATE or PUBLIC)", "PRIVATE").option("--language <language>", "Project language", "Java").action(async (options, cmd) => {
|
|
2086
2557
|
try {
|
|
2087
2558
|
const outputFormat = getOutputFormat(cmd);
|
|
2088
2559
|
const api = createApiClient();
|
|
@@ -2092,8 +2563,8 @@ function registerProjectCommands(program) {
|
|
|
2092
2563
|
active: true
|
|
2093
2564
|
});
|
|
2094
2565
|
if (outputFormat === "human") {
|
|
2095
|
-
console.log(
|
|
2096
|
-
console.log(` Project ID: ${
|
|
2566
|
+
console.log(chalk9.green("Project created."));
|
|
2567
|
+
console.log(` Project ID: ${chalk9.bold(p.projectId)}`);
|
|
2097
2568
|
console.log(` Visibility: ${p.visibility}`);
|
|
2098
2569
|
console.log(` Language: ${p.language}`);
|
|
2099
2570
|
} else {
|
|
@@ -2115,7 +2586,7 @@ function registerProjectCommands(program) {
|
|
|
2115
2586
|
...options.active !== void 0 ? { active: options.active === "true" } : {}
|
|
2116
2587
|
};
|
|
2117
2588
|
await api.admin.updateProject(updated);
|
|
2118
|
-
console.log(
|
|
2589
|
+
console.log(chalk9.green(`Project "${projectId}" updated.`));
|
|
2119
2590
|
} catch (error) {
|
|
2120
2591
|
handleError(error);
|
|
2121
2592
|
}
|
|
@@ -2137,7 +2608,7 @@ function registerProjectCommands(program) {
|
|
|
2137
2608
|
try {
|
|
2138
2609
|
const api = createApiClient();
|
|
2139
2610
|
await api.admin.deleteProject(projectId);
|
|
2140
|
-
console.log(
|
|
2611
|
+
console.log(chalk9.green(`Project "${projectId}" deleted.`));
|
|
2141
2612
|
} catch (error) {
|
|
2142
2613
|
handleError(error);
|
|
2143
2614
|
}
|
|
@@ -2146,7 +2617,7 @@ function registerProjectCommands(program) {
|
|
|
2146
2617
|
try {
|
|
2147
2618
|
const api = createApiClient();
|
|
2148
2619
|
await api.admin.lockProject(projectId);
|
|
2149
|
-
console.log(
|
|
2620
|
+
console.log(chalk9.green(`Project "${projectId}" locked.`));
|
|
2150
2621
|
} catch (error) {
|
|
2151
2622
|
handleError(error);
|
|
2152
2623
|
}
|
|
@@ -2155,7 +2626,7 @@ function registerProjectCommands(program) {
|
|
|
2155
2626
|
try {
|
|
2156
2627
|
const api = createApiClient();
|
|
2157
2628
|
await api.admin.unlockProject(projectId);
|
|
2158
|
-
console.log(
|
|
2629
|
+
console.log(chalk9.green(`Project "${projectId}" unlocked.`));
|
|
2159
2630
|
} catch (error) {
|
|
2160
2631
|
handleError(error);
|
|
2161
2632
|
}
|
|
@@ -2178,7 +2649,7 @@ function registerProjectCommands(program) {
|
|
|
2178
2649
|
try {
|
|
2179
2650
|
const api = createApiClient();
|
|
2180
2651
|
await api.admin.inviteProjectMember(projectId, userId, role.toUpperCase());
|
|
2181
|
-
console.log(
|
|
2652
|
+
console.log(chalk9.green(`Invited ${userId} to "${projectId}" as ${role.toUpperCase()}.`));
|
|
2182
2653
|
} catch (error) {
|
|
2183
2654
|
handleError(error);
|
|
2184
2655
|
}
|
|
@@ -2187,7 +2658,7 @@ function registerProjectCommands(program) {
|
|
|
2187
2658
|
try {
|
|
2188
2659
|
const api = createApiClient();
|
|
2189
2660
|
await api.admin.joinProject(projectId, userId);
|
|
2190
|
-
console.log(
|
|
2661
|
+
console.log(chalk9.green(`Joined project "${projectId}".`));
|
|
2191
2662
|
} catch (error) {
|
|
2192
2663
|
handleError(error);
|
|
2193
2664
|
}
|
|
@@ -2196,90 +2667,54 @@ function registerProjectCommands(program) {
|
|
|
2196
2667
|
try {
|
|
2197
2668
|
const api = createApiClient();
|
|
2198
2669
|
await api.admin.removeProjectMember(projectId, userId);
|
|
2199
|
-
console.log(
|
|
2670
|
+
console.log(chalk9.green(`Removed ${userId} from "${projectId}".`));
|
|
2200
2671
|
} catch (error) {
|
|
2201
2672
|
handleError(error);
|
|
2202
2673
|
}
|
|
2203
2674
|
});
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
entityId,
|
|
2224
|
-
entityBranch: entityBranch || defaultBranch
|
|
2225
|
-
};
|
|
2226
|
-
}
|
|
2227
|
-
const parts = ref.split("/");
|
|
2228
|
-
if (parts.length === 1) {
|
|
2229
|
-
if (!defaultProject) {
|
|
2230
|
-
throw new Error("No default project configured. Set one with: diafunc config set defaults.project <id>");
|
|
2675
|
+
project.command("export").description("Export a whole project (entities, links, skeletons, analysis recipe) to a .dfproj bundle").argument("<project>", "Project reference (projectId or projectId/branch)").option("--out <file>", "Output file (defaults to project.dfproj)").option("--async", "Queue the background job and return immediately instead of waiting for the file").action(async (project2, options, cmd) => {
|
|
2676
|
+
try {
|
|
2677
|
+
const overrides = getOverrides(cmd);
|
|
2678
|
+
const ref = parseProjectReference(project2, overrides);
|
|
2679
|
+
const api = createApiClient();
|
|
2680
|
+
const bundleId = await api.storage.exportProjectBundle(ref.projectId, ref.projectBranch);
|
|
2681
|
+
if (options.async) {
|
|
2682
|
+
console.log(chalk9.green(`Project export queued (bundle ID: ${bundleId}).`));
|
|
2683
|
+
console.log(`Poll progress: diafunc notebook bundles ${project2}`);
|
|
2684
|
+
return;
|
|
2685
|
+
}
|
|
2686
|
+
console.log(chalk9.dim(`Project export queued (bundle ID: ${bundleId}); waiting for it to finish\u2026`));
|
|
2687
|
+
const job = await pollUntilFinished(api.storage, ref.projectId, ref.projectBranch, bundleId);
|
|
2688
|
+
const response = await api.storage.getBundleContent(ref.projectId, ref.projectBranch, bundleId, job.filename);
|
|
2689
|
+
const outFile = options.out ?? "project.dfproj";
|
|
2690
|
+
const bytes = await streamResponseToFile(response, outFile);
|
|
2691
|
+
console.log(chalk9.green(`Bundle written to ${outFile} (${bytes} bytes, ${job.entityCount ?? "?"} entities).`));
|
|
2692
|
+
} catch (error) {
|
|
2693
|
+
handleError(error);
|
|
2231
2694
|
}
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
projectBranch: defaultBranch,
|
|
2243
|
-
entityId: parts[1],
|
|
2244
|
-
entityBranch: defaultBranch
|
|
2245
|
-
};
|
|
2246
|
-
}
|
|
2247
|
-
if (parts.length === 3) {
|
|
2248
|
-
if (parts[1] === "") {
|
|
2249
|
-
return {
|
|
2250
|
-
projectId: parts[0],
|
|
2251
|
-
projectBranch: defaultBranch,
|
|
2252
|
-
entityId: parts[2],
|
|
2253
|
-
entityBranch: defaultBranch
|
|
2254
|
-
};
|
|
2695
|
+
});
|
|
2696
|
+
project.command("import").description("Import a .dfproj (or any) bundle into a project").argument("<project>", "Target project reference (projectId or projectId/branch)").argument("<file>", "Path to the bundle").option("--on-conflict <policy>", "copy (default), overwrite, or skip", "copy").option("--preview", "Show the bundle inventory without importing").action(async (project2, file, options, cmd) => {
|
|
2697
|
+
try {
|
|
2698
|
+
const outputFormat = getOutputFormat(cmd);
|
|
2699
|
+
const overrides = getOverrides(cmd);
|
|
2700
|
+
const ref = parseProjectReference(project2, overrides);
|
|
2701
|
+
const api = createApiClient();
|
|
2702
|
+
await runBundleImport(api.storage, ref.projectId, ref.projectBranch, file, options, outputFormat);
|
|
2703
|
+
} catch (error) {
|
|
2704
|
+
handleError(error);
|
|
2255
2705
|
}
|
|
2256
|
-
|
|
2257
|
-
projectId: parts[0],
|
|
2258
|
-
projectBranch: parts[1],
|
|
2259
|
-
entityId: parts[2],
|
|
2260
|
-
entityBranch: defaultBranch
|
|
2261
|
-
};
|
|
2262
|
-
}
|
|
2263
|
-
if (parts.length === 4) {
|
|
2264
|
-
return {
|
|
2265
|
-
projectId: parts[0],
|
|
2266
|
-
projectBranch: parts[1] || defaultBranch,
|
|
2267
|
-
entityId: parts[2],
|
|
2268
|
-
entityBranch: parts[3] || defaultBranch
|
|
2269
|
-
};
|
|
2270
|
-
}
|
|
2271
|
-
throw new Error(
|
|
2272
|
-
`Invalid entity reference: "${ref}". Expected format: entityId, entityId:branch, or projectId/projectBranch/entityId/entityBranch`
|
|
2273
|
-
);
|
|
2706
|
+
});
|
|
2274
2707
|
}
|
|
2275
2708
|
|
|
2276
2709
|
// src/commands/entity/index.ts
|
|
2710
|
+
import chalk10 from "chalk";
|
|
2711
|
+
import * as fs3 from "fs";
|
|
2277
2712
|
function getOutputFormat2(cmd) {
|
|
2278
2713
|
const config = loadConfig();
|
|
2279
2714
|
const globalOpts = cmd.optsWithGlobals();
|
|
2280
2715
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
2281
2716
|
}
|
|
2282
|
-
function
|
|
2717
|
+
function getOverrides2(cmd) {
|
|
2283
2718
|
const opts = cmd.optsWithGlobals();
|
|
2284
2719
|
return { project: opts.project, branch: opts.branch };
|
|
2285
2720
|
}
|
|
@@ -2288,7 +2723,7 @@ function registerEntityCommands(program) {
|
|
|
2288
2723
|
entity.command("list").description("List entities in a project (via linked entities from project root)").argument("<projectRef>", "Project reference (projectId or projectId/branch)").action(async (projectRef, _options, cmd) => {
|
|
2289
2724
|
try {
|
|
2290
2725
|
const outputFormat = getOutputFormat2(cmd);
|
|
2291
|
-
const overrides =
|
|
2726
|
+
const overrides = getOverrides2(cmd);
|
|
2292
2727
|
const ref = parseEntityReference(projectRef + "/" + projectRef, overrides);
|
|
2293
2728
|
const api = createApiClient();
|
|
2294
2729
|
const entities = await api.storage.getLinkedEntities("FORWARD", {
|
|
@@ -2315,7 +2750,7 @@ function registerEntityCommands(program) {
|
|
|
2315
2750
|
entity.command("get").description("Get entity metadata").argument("<ref>", "Entity reference").option("--content", "Include content").action(async (ref, options, cmd) => {
|
|
2316
2751
|
try {
|
|
2317
2752
|
const outputFormat = getOutputFormat2(cmd);
|
|
2318
|
-
const overrides =
|
|
2753
|
+
const overrides = getOverrides2(cmd);
|
|
2319
2754
|
const resolved = parseEntityReference(ref, overrides);
|
|
2320
2755
|
const api = createApiClient();
|
|
2321
2756
|
const e = await api.storage.getEntity(resolved, options.content);
|
|
@@ -2345,11 +2780,11 @@ function registerEntityCommands(program) {
|
|
|
2345
2780
|
});
|
|
2346
2781
|
entity.command("delete").description("Delete an entity").argument("<ref>", "Entity reference").action(async (ref, _options, cmd) => {
|
|
2347
2782
|
try {
|
|
2348
|
-
const overrides =
|
|
2783
|
+
const overrides = getOverrides2(cmd);
|
|
2349
2784
|
const resolved = parseEntityReference(ref, overrides);
|
|
2350
2785
|
const api = createApiClient();
|
|
2351
2786
|
await api.storage.deleteEntity(resolved);
|
|
2352
|
-
console.log(
|
|
2787
|
+
console.log(chalk10.green(`Entity "${resolved.entityId}" deleted.`));
|
|
2353
2788
|
} catch (error) {
|
|
2354
2789
|
handleError(error);
|
|
2355
2790
|
}
|
|
@@ -2357,7 +2792,7 @@ function registerEntityCommands(program) {
|
|
|
2357
2792
|
entity.command("history").description("Get entity version history").argument("<ref>", "Entity reference").option("--from <version>", "From version").option("--to <version>", "To version").action(async (ref, options, cmd) => {
|
|
2358
2793
|
try {
|
|
2359
2794
|
const outputFormat = getOutputFormat2(cmd);
|
|
2360
|
-
const overrides =
|
|
2795
|
+
const overrides = getOverrides2(cmd);
|
|
2361
2796
|
const resolved = parseEntityReference(ref, overrides);
|
|
2362
2797
|
const api = createApiClient();
|
|
2363
2798
|
if (options.from && options.to) {
|
|
@@ -2386,22 +2821,22 @@ function registerEntityCommands(program) {
|
|
|
2386
2821
|
});
|
|
2387
2822
|
entity.command("revert").description("Revert an entity to a previous version").argument("<ref>", "Entity reference").argument("<version>", "Version to revert to").action(async (ref, version, _options, cmd) => {
|
|
2388
2823
|
try {
|
|
2389
|
-
const overrides =
|
|
2824
|
+
const overrides = getOverrides2(cmd);
|
|
2390
2825
|
const resolved = parseEntityReference(ref, overrides);
|
|
2391
2826
|
const api = createApiClient();
|
|
2392
2827
|
await api.storage.revertEntity(resolved, parseInt(version, 10));
|
|
2393
|
-
console.log(
|
|
2828
|
+
console.log(chalk10.green(`Entity "${resolved.entityId}" reverted to version ${version}.`));
|
|
2394
2829
|
} catch (error) {
|
|
2395
2830
|
handleError(error);
|
|
2396
2831
|
}
|
|
2397
2832
|
});
|
|
2398
2833
|
entity.command("rename").description("Rename an entity").argument("<ref>", "Entity reference").argument("<newId>", "New entity ID").action(async (ref, newId, _options, cmd) => {
|
|
2399
2834
|
try {
|
|
2400
|
-
const overrides =
|
|
2835
|
+
const overrides = getOverrides2(cmd);
|
|
2401
2836
|
const resolved = parseEntityReference(ref, overrides);
|
|
2402
2837
|
const api = createApiClient();
|
|
2403
2838
|
await api.storage.renameEntity(resolved, newId);
|
|
2404
|
-
console.log(
|
|
2839
|
+
console.log(chalk10.green(`Entity renamed from "${resolved.entityId}" to "${newId}".`));
|
|
2405
2840
|
} catch (error) {
|
|
2406
2841
|
handleError(error);
|
|
2407
2842
|
}
|
|
@@ -2409,14 +2844,14 @@ function registerEntityCommands(program) {
|
|
|
2409
2844
|
const content = entity.command("content").description("Manage entity content");
|
|
2410
2845
|
content.command("get").description("Download entity content").argument("<ref>", "Entity reference").option("--out <file>", "Output file (defaults to stdout)").action(async (ref, options, cmd) => {
|
|
2411
2846
|
try {
|
|
2412
|
-
const overrides =
|
|
2847
|
+
const overrides = getOverrides2(cmd);
|
|
2413
2848
|
const resolved = parseEntityReference(ref, overrides);
|
|
2414
2849
|
const api = createApiClient();
|
|
2415
2850
|
const response = await api.storage.getEntityContent(resolved);
|
|
2416
2851
|
if (options.out) {
|
|
2417
2852
|
const buffer = Buffer.from(await response.arrayBuffer());
|
|
2418
|
-
|
|
2419
|
-
console.log(
|
|
2853
|
+
fs3.writeFileSync(options.out, buffer);
|
|
2854
|
+
console.log(chalk10.green(`Content saved to ${options.out}`));
|
|
2420
2855
|
} else {
|
|
2421
2856
|
const text = await response.text();
|
|
2422
2857
|
process.stdout.write(text);
|
|
@@ -2427,24 +2862,55 @@ function registerEntityCommands(program) {
|
|
|
2427
2862
|
});
|
|
2428
2863
|
content.command("set").description("Upload entity content from a file").argument("<ref>", "Entity reference").argument("<file>", "File to upload").action(async (ref, file, _options, cmd) => {
|
|
2429
2864
|
try {
|
|
2430
|
-
const overrides =
|
|
2865
|
+
const overrides = getOverrides2(cmd);
|
|
2431
2866
|
const resolved = parseEntityReference(ref, overrides);
|
|
2432
2867
|
const api = createApiClient();
|
|
2433
|
-
const fileBuffer =
|
|
2868
|
+
const fileBuffer = fs3.readFileSync(file);
|
|
2434
2869
|
const base64 = fileBuffer.toString("base64");
|
|
2435
2870
|
await api.storage.saveEntityContentBase64(resolved, base64);
|
|
2436
|
-
console.log(
|
|
2871
|
+
console.log(chalk10.green(`Content uploaded from "${file}" to entity "${resolved.entityId}".`));
|
|
2437
2872
|
} catch (error) {
|
|
2438
2873
|
handleError(error);
|
|
2439
2874
|
}
|
|
2440
2875
|
});
|
|
2441
2876
|
content.command("delete").description("Delete entity content").argument("<ref>", "Entity reference").action(async (ref, _options, cmd) => {
|
|
2442
2877
|
try {
|
|
2443
|
-
const overrides =
|
|
2878
|
+
const overrides = getOverrides2(cmd);
|
|
2444
2879
|
const resolved = parseEntityReference(ref, overrides);
|
|
2445
2880
|
const api = createApiClient();
|
|
2446
2881
|
await api.storage.deleteEntityContent(resolved);
|
|
2447
|
-
console.log(
|
|
2882
|
+
console.log(chalk10.green(`Content deleted from entity "${resolved.entityId}".`));
|
|
2883
|
+
} catch (error) {
|
|
2884
|
+
handleError(error);
|
|
2885
|
+
}
|
|
2886
|
+
});
|
|
2887
|
+
entity.command("export").description("Export a subset of entities (plus their closure) to a .dfset bundle").argument("<project>", "Project reference (projectId or projectId/branch)").argument("<entityIds...>", "Entity id(s) to export").option("--out <file>", "Output file (defaults to entities.dfset)").option("--data <encoding>", "Embedded table-data encoding: csv (default) or parquet", "csv").option("--async", "Queue a background job instead of streaming the download now").action(async (project, entityIds, options, cmd) => {
|
|
2888
|
+
try {
|
|
2889
|
+
const overrides = getOverrides2(cmd);
|
|
2890
|
+
const ref = parseProjectReference(project, overrides);
|
|
2891
|
+
const api = createApiClient();
|
|
2892
|
+
const request = { rootEntityIds: entityIds, dataFormat: options.data };
|
|
2893
|
+
if (options.async) {
|
|
2894
|
+
const bundleId = await api.storage.exportEntitySubset(ref.projectId, ref.projectBranch, request);
|
|
2895
|
+
console.log(chalk10.green(`Export queued (bundle ID: ${bundleId}).`));
|
|
2896
|
+
console.log(`Poll progress: diafunc notebook bundles ${project}`);
|
|
2897
|
+
return;
|
|
2898
|
+
}
|
|
2899
|
+
const response = await api.storage.streamEntitySubset(ref.projectId, ref.projectBranch, request);
|
|
2900
|
+
const outFile = options.out ?? "entities.dfset";
|
|
2901
|
+
const bytes = await streamResponseToFile(response, outFile);
|
|
2902
|
+
console.log(chalk10.green(`Bundle written to ${outFile} (${bytes} bytes, ${entityIds.length} entity(ies)).`));
|
|
2903
|
+
} catch (error) {
|
|
2904
|
+
handleError(error);
|
|
2905
|
+
}
|
|
2906
|
+
});
|
|
2907
|
+
entity.command("import").description("Import a .dfset (or any) bundle into a project").argument("<project>", "Target project reference (projectId or projectId/branch)").argument("<file>", "Path to the bundle").option("--on-conflict <policy>", "copy (default), overwrite, or skip", "copy").option("--preview", "Show the bundle inventory without importing").action(async (project, file, options, cmd) => {
|
|
2908
|
+
try {
|
|
2909
|
+
const outputFormat = getOutputFormat2(cmd);
|
|
2910
|
+
const overrides = getOverrides2(cmd);
|
|
2911
|
+
const ref = parseProjectReference(project, overrides);
|
|
2912
|
+
const api = createApiClient();
|
|
2913
|
+
await runBundleImport(api.storage, ref.projectId, ref.projectBranch, file, options, outputFormat);
|
|
2448
2914
|
} catch (error) {
|
|
2449
2915
|
handleError(error);
|
|
2450
2916
|
}
|
|
@@ -2452,13 +2918,13 @@ function registerEntityCommands(program) {
|
|
|
2452
2918
|
}
|
|
2453
2919
|
|
|
2454
2920
|
// src/commands/link/index.ts
|
|
2455
|
-
import
|
|
2921
|
+
import chalk11 from "chalk";
|
|
2456
2922
|
function getOutputFormat3(cmd) {
|
|
2457
2923
|
const config = loadConfig();
|
|
2458
2924
|
const globalOpts = cmd.optsWithGlobals();
|
|
2459
2925
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
2460
2926
|
}
|
|
2461
|
-
function
|
|
2927
|
+
function getOverrides3(cmd) {
|
|
2462
2928
|
const opts = cmd.optsWithGlobals();
|
|
2463
2929
|
return { project: opts.project, branch: opts.branch };
|
|
2464
2930
|
}
|
|
@@ -2467,7 +2933,7 @@ function registerLinkCommands(program) {
|
|
|
2467
2933
|
link.command("list").description("List links for an entity").argument("<ref>", "Source entity reference").option("--direction <dir>", "Link direction: FORWARD or BACKWARD", "FORWARD").action(async (ref, options, cmd) => {
|
|
2468
2934
|
try {
|
|
2469
2935
|
const outputFormat = getOutputFormat3(cmd);
|
|
2470
|
-
const overrides =
|
|
2936
|
+
const overrides = getOverrides3(cmd);
|
|
2471
2937
|
const resolved = parseEntityReference(ref, overrides);
|
|
2472
2938
|
const api = createApiClient();
|
|
2473
2939
|
const direction = options.direction.toUpperCase();
|
|
@@ -2489,7 +2955,7 @@ function registerLinkCommands(program) {
|
|
|
2489
2955
|
});
|
|
2490
2956
|
link.command("create").description("Create a link between two entities").argument("<sourceRef>", "Source entity reference").argument("<linkId>", "Link ID").argument("<targetRef>", "Target entity reference").action(async (sourceRef, linkId, targetRef, _options, cmd) => {
|
|
2491
2957
|
try {
|
|
2492
|
-
const overrides =
|
|
2958
|
+
const overrides = getOverrides3(cmd);
|
|
2493
2959
|
const source = parseEntityReference(sourceRef, overrides);
|
|
2494
2960
|
const target = parseEntityReference(targetRef, overrides);
|
|
2495
2961
|
const api = createApiClient();
|
|
@@ -2502,14 +2968,14 @@ function registerLinkCommands(program) {
|
|
|
2502
2968
|
target.entityId,
|
|
2503
2969
|
target.entityBranch
|
|
2504
2970
|
);
|
|
2505
|
-
console.log(
|
|
2971
|
+
console.log(chalk11.green(`Link "${linkId}" created: ${source.entityId} \u2192 ${target.entityId}`));
|
|
2506
2972
|
} catch (error) {
|
|
2507
2973
|
handleError(error);
|
|
2508
2974
|
}
|
|
2509
2975
|
});
|
|
2510
2976
|
link.command("delete").description("Delete a link").argument("<sourceRef>", "Source entity reference").argument("<linkId>", "Link ID").argument("[targetRef]", "Target entity reference (optional, deletes all targets if omitted)").action(async (sourceRef, linkId, targetRef, _options, cmd) => {
|
|
2511
2977
|
try {
|
|
2512
|
-
const overrides =
|
|
2978
|
+
const overrides = getOverrides3(cmd);
|
|
2513
2979
|
const source = parseEntityReference(sourceRef, overrides);
|
|
2514
2980
|
const api = createApiClient();
|
|
2515
2981
|
if (targetRef) {
|
|
@@ -2523,7 +2989,7 @@ function registerLinkCommands(program) {
|
|
|
2523
2989
|
target.entityId,
|
|
2524
2990
|
target.entityBranch
|
|
2525
2991
|
);
|
|
2526
|
-
console.log(
|
|
2992
|
+
console.log(chalk11.green(`Link "${linkId}" deleted: ${source.entityId} \u2192 ${target.entityId}`));
|
|
2527
2993
|
} else {
|
|
2528
2994
|
await api.storage.deleteLink(
|
|
2529
2995
|
source.projectId,
|
|
@@ -2532,7 +2998,7 @@ function registerLinkCommands(program) {
|
|
|
2532
2998
|
source.entityBranch,
|
|
2533
2999
|
linkId
|
|
2534
3000
|
);
|
|
2535
|
-
console.log(
|
|
3001
|
+
console.log(chalk11.green(`All links with ID "${linkId}" from "${source.entityId}" deleted.`));
|
|
2536
3002
|
}
|
|
2537
3003
|
} catch (error) {
|
|
2538
3004
|
handleError(error);
|
|
@@ -2541,13 +3007,13 @@ function registerLinkCommands(program) {
|
|
|
2541
3007
|
}
|
|
2542
3008
|
|
|
2543
3009
|
// src/commands/event/index.ts
|
|
2544
|
-
import
|
|
3010
|
+
import chalk12 from "chalk";
|
|
2545
3011
|
function getOutputFormat4(cmd) {
|
|
2546
3012
|
const config = loadConfig();
|
|
2547
3013
|
const globalOpts = cmd.optsWithGlobals();
|
|
2548
3014
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
2549
3015
|
}
|
|
2550
|
-
function
|
|
3016
|
+
function getOverrides4(cmd) {
|
|
2551
3017
|
const opts = cmd.optsWithGlobals();
|
|
2552
3018
|
return { project: opts.project, branch: opts.branch };
|
|
2553
3019
|
}
|
|
@@ -2556,7 +3022,7 @@ function registerEventCommands(program) {
|
|
|
2556
3022
|
event.command("list").description("List events for an entity").argument("<ref>", "Entity reference").action(async (ref, _options, cmd) => {
|
|
2557
3023
|
try {
|
|
2558
3024
|
const outputFormat = getOutputFormat4(cmd);
|
|
2559
|
-
const overrides =
|
|
3025
|
+
const overrides = getOverrides4(cmd);
|
|
2560
3026
|
const resolved = parseEntityReference(ref, overrides);
|
|
2561
3027
|
const api = createApiClient();
|
|
2562
3028
|
const events = await api.storage.getEvents(resolved);
|
|
@@ -2578,7 +3044,7 @@ function registerEventCommands(program) {
|
|
|
2578
3044
|
event.command("get").description("Get a specific event").argument("<ref>", "Entity reference").argument("<eventId>", "Event ID").argument("<occurrenceId>", "Occurrence ID").action(async (ref, eventId, occurrenceId, _options, cmd) => {
|
|
2579
3045
|
try {
|
|
2580
3046
|
const outputFormat = getOutputFormat4(cmd);
|
|
2581
|
-
const overrides =
|
|
3047
|
+
const overrides = getOverrides4(cmd);
|
|
2582
3048
|
const resolved = parseEntityReference(ref, overrides);
|
|
2583
3049
|
const api = createApiClient();
|
|
2584
3050
|
const event2 = await api.storage.getEvent(resolved, eventId, occurrenceId);
|
|
@@ -2589,8 +3055,8 @@ function registerEventCommands(program) {
|
|
|
2589
3055
|
});
|
|
2590
3056
|
event.command("create").description("Create one or more events (body from JSON file or stdin)").argument("[file]", "JSON file containing a BareEvent array; defaults to stdin").action(async (file) => {
|
|
2591
3057
|
try {
|
|
2592
|
-
const
|
|
2593
|
-
const body = file ?
|
|
3058
|
+
const fs14 = await import("fs");
|
|
3059
|
+
const body = file ? fs14.readFileSync(file, "utf-8") : await new Promise((resolve, reject) => {
|
|
2594
3060
|
let data = "";
|
|
2595
3061
|
process.stdin.setEncoding("utf-8");
|
|
2596
3062
|
process.stdin.on("data", (chunk) => {
|
|
@@ -2603,7 +3069,7 @@ function registerEventCommands(program) {
|
|
|
2603
3069
|
const api = createApiClient();
|
|
2604
3070
|
const arr = Array.isArray(events) ? events : [events];
|
|
2605
3071
|
await api.storage.createEvents(arr);
|
|
2606
|
-
console.log(
|
|
3072
|
+
console.log(chalk12.green(`${arr.length} event(s) created.`));
|
|
2607
3073
|
} catch (error) {
|
|
2608
3074
|
handleError(error);
|
|
2609
3075
|
}
|
|
@@ -2626,11 +3092,11 @@ function registerEventCommands(program) {
|
|
|
2626
3092
|
});
|
|
2627
3093
|
event.command("delete").description("Delete an event").argument("<ref>", "Entity reference").argument("<eventId>", "Event ID").argument("<occurrenceId>", "Occurrence ID").action(async (ref, eventId, occurrenceId, _options, cmd) => {
|
|
2628
3094
|
try {
|
|
2629
|
-
const overrides =
|
|
3095
|
+
const overrides = getOverrides4(cmd);
|
|
2630
3096
|
const resolved = parseEntityReference(ref, overrides);
|
|
2631
3097
|
const api = createApiClient();
|
|
2632
3098
|
await api.storage.deleteEvent(resolved, eventId, occurrenceId);
|
|
2633
|
-
console.log(
|
|
3099
|
+
console.log(chalk12.green(`Event "${eventId}/${occurrenceId}" deleted.`));
|
|
2634
3100
|
} catch (error) {
|
|
2635
3101
|
handleError(error);
|
|
2636
3102
|
}
|
|
@@ -2638,13 +3104,13 @@ function registerEventCommands(program) {
|
|
|
2638
3104
|
}
|
|
2639
3105
|
|
|
2640
3106
|
// src/commands/branch/index.ts
|
|
2641
|
-
import
|
|
3107
|
+
import chalk13 from "chalk";
|
|
2642
3108
|
function getOutputFormat5(cmd) {
|
|
2643
3109
|
const config = loadConfig();
|
|
2644
3110
|
const globalOpts = cmd.optsWithGlobals();
|
|
2645
3111
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
2646
3112
|
}
|
|
2647
|
-
function
|
|
3113
|
+
function getOverrides5(cmd) {
|
|
2648
3114
|
const opts = cmd.optsWithGlobals();
|
|
2649
3115
|
return { project: opts.project, branch: opts.branch };
|
|
2650
3116
|
}
|
|
@@ -2653,11 +3119,11 @@ function registerBranchCommands(program) {
|
|
|
2653
3119
|
branch.command("list").description("List branches for a project").argument("[projectId]", "Project ID (uses default if omitted)").action(async (projectId, _options, cmd) => {
|
|
2654
3120
|
try {
|
|
2655
3121
|
const outputFormat = getOutputFormat5(cmd);
|
|
2656
|
-
const overrides =
|
|
3122
|
+
const overrides = getOverrides5(cmd);
|
|
2657
3123
|
const config = loadConfig();
|
|
2658
3124
|
const pid = projectId ?? overrides.project ?? config.defaults.project;
|
|
2659
3125
|
if (!pid) {
|
|
2660
|
-
console.error(
|
|
3126
|
+
console.error(chalk13.red("No project specified. Pass a project ID or set defaults.project."));
|
|
2661
3127
|
process.exit(1);
|
|
2662
3128
|
}
|
|
2663
3129
|
const api = createApiClient();
|
|
@@ -2681,7 +3147,7 @@ function registerBranchCommands(program) {
|
|
|
2681
3147
|
sourceProjectBranch: options.source,
|
|
2682
3148
|
targetProjectBranch: branchName
|
|
2683
3149
|
});
|
|
2684
|
-
console.log(
|
|
3150
|
+
console.log(chalk13.green(`Branch "${branchName}" created in project "${projectId}" from "${options.source}".`));
|
|
2685
3151
|
} catch (error) {
|
|
2686
3152
|
handleError(error);
|
|
2687
3153
|
}
|
|
@@ -2690,14 +3156,14 @@ function registerBranchCommands(program) {
|
|
|
2690
3156
|
try {
|
|
2691
3157
|
const api = createApiClient();
|
|
2692
3158
|
await api.storage.deleteProjectBranch(projectId, branchName);
|
|
2693
|
-
console.log(
|
|
3159
|
+
console.log(chalk13.green(`Branch "${branchName}" deleted from project "${projectId}".`));
|
|
2694
3160
|
} catch (error) {
|
|
2695
3161
|
handleError(error);
|
|
2696
3162
|
}
|
|
2697
3163
|
});
|
|
2698
3164
|
branch.command("merge").description("Merge an entity from one branch to another").requiredOption("--source <ref>", "Source entity reference (projectId/branch/entityId/entityBranch)").requiredOption("--target <ref>", "Target project reference (projectId/branch)").option("--link-id <linkId>", "Link ID for the merge", "main").option("--deep", "Deep merge (include linked entities)", false).action(async (options, cmd) => {
|
|
2699
3165
|
try {
|
|
2700
|
-
const overrides =
|
|
3166
|
+
const overrides = getOverrides5(cmd);
|
|
2701
3167
|
const source = parseEntityReference(options.source, overrides);
|
|
2702
3168
|
const targetParts = options.target.split("/");
|
|
2703
3169
|
const api = createApiClient();
|
|
@@ -2711,7 +3177,7 @@ function registerBranchCommands(program) {
|
|
|
2711
3177
|
linkId: options.linkId,
|
|
2712
3178
|
deepMerge: options.deep
|
|
2713
3179
|
});
|
|
2714
|
-
console.log(
|
|
3180
|
+
console.log(chalk13.green("Merge completed."));
|
|
2715
3181
|
} catch (error) {
|
|
2716
3182
|
handleError(error);
|
|
2717
3183
|
}
|
|
@@ -2726,7 +3192,7 @@ function registerBranchCommands(program) {
|
|
|
2726
3192
|
forkProjectName: options.name ?? forkProjectId,
|
|
2727
3193
|
forkProjectDescription: options.description
|
|
2728
3194
|
});
|
|
2729
|
-
console.log(
|
|
3195
|
+
console.log(chalk13.green(`Project "${projectId}" forked to "${forkProjectId}".`));
|
|
2730
3196
|
} catch (error) {
|
|
2731
3197
|
handleError(error);
|
|
2732
3198
|
}
|
|
@@ -2734,24 +3200,37 @@ function registerBranchCommands(program) {
|
|
|
2734
3200
|
}
|
|
2735
3201
|
|
|
2736
3202
|
// src/commands/table/index.ts
|
|
2737
|
-
import
|
|
2738
|
-
import * as
|
|
2739
|
-
import * as
|
|
3203
|
+
import chalk14 from "chalk";
|
|
3204
|
+
import * as fs4 from "fs";
|
|
3205
|
+
import * as path3 from "path";
|
|
2740
3206
|
function getOutputFormat6(cmd) {
|
|
2741
3207
|
const config = loadConfig();
|
|
2742
3208
|
const globalOpts = cmd.optsWithGlobals();
|
|
2743
3209
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
2744
3210
|
}
|
|
2745
|
-
function
|
|
3211
|
+
function getOverrides6(cmd) {
|
|
2746
3212
|
const opts = cmd.optsWithGlobals();
|
|
2747
3213
|
return { project: opts.project, branch: opts.branch };
|
|
2748
3214
|
}
|
|
3215
|
+
function deriveOutFile(entityId, extension, archive, compression) {
|
|
3216
|
+
let name = `${entityId}${extension}`;
|
|
3217
|
+
if (archive === "zip") {
|
|
3218
|
+
name += ".zip";
|
|
3219
|
+
} else if (archive === "tar") {
|
|
3220
|
+
name += ".tar";
|
|
3221
|
+
}
|
|
3222
|
+
if (archive !== "zip" && compression) {
|
|
3223
|
+
const suffix = { gzip: ".gz", bzip2: ".bz2", xz: ".xz", zstd: ".zst" };
|
|
3224
|
+
name += suffix[compression] ?? "";
|
|
3225
|
+
}
|
|
3226
|
+
return name;
|
|
3227
|
+
}
|
|
2749
3228
|
function registerTableCommands(program) {
|
|
2750
3229
|
const table = program.command("table").description("Manage tables");
|
|
2751
3230
|
table.command("view").description("View table data").argument("<ref>", "Table entity reference").option("--rows <range>", "Row range (e.g., 0:10)").option("--cols <range>", "Column range (e.g., 0:5)").action(async (ref, options, cmd) => {
|
|
2752
3231
|
try {
|
|
2753
3232
|
const outputFormat = getOutputFormat6(cmd);
|
|
2754
|
-
const overrides =
|
|
3233
|
+
const overrides = getOverrides6(cmd);
|
|
2755
3234
|
const resolved = parseEntityReference(ref, overrides);
|
|
2756
3235
|
const api = createApiClient();
|
|
2757
3236
|
const request = {};
|
|
@@ -2791,94 +3270,193 @@ function registerTableCommands(program) {
|
|
|
2791
3270
|
console.log(colNames.map((c) => row2[c] ?? "").join(" "));
|
|
2792
3271
|
}
|
|
2793
3272
|
} else {
|
|
2794
|
-
console.log(
|
|
3273
|
+
console.log(chalk14.dim(`${snapshot.rows.length} rows \xD7 ${snapshot.columns.length} columns`));
|
|
2795
3274
|
format(tableData, { format: outputFormat, columns: colNames });
|
|
2796
3275
|
}
|
|
2797
3276
|
} catch (error) {
|
|
2798
3277
|
handleError(error);
|
|
2799
3278
|
}
|
|
2800
3279
|
});
|
|
2801
|
-
table.command("import").description("Import data from a
|
|
3280
|
+
table.command("import").description("Import data from a file (any supported format \u2014 see `table import-formats`)").argument("<ref>", "Table entity reference").argument("<file>", "File to import").option("--selection <id>", "Pin a sheet / inner-table id for multi-table sources (Excel sheets, SQLite tables, archive entries)").action(async (ref, file, options, cmd) => {
|
|
3281
|
+
try {
|
|
3282
|
+
const overrides = getOverrides6(cmd);
|
|
3283
|
+
const resolved = parseEntityReference(ref, overrides);
|
|
3284
|
+
if (!fs4.existsSync(file)) {
|
|
3285
|
+
console.error(chalk14.red(`File not found: ${file}`));
|
|
3286
|
+
process.exit(1);
|
|
3287
|
+
}
|
|
3288
|
+
const api = createApiClient();
|
|
3289
|
+
const fileBuffer = fs4.readFileSync(file);
|
|
3290
|
+
const blob = new Blob([fileBuffer]);
|
|
3291
|
+
const formData = new FormData();
|
|
3292
|
+
formData.append("content", blob, path3.basename(file));
|
|
3293
|
+
console.log(`Importing ${path3.basename(file)} ...`);
|
|
3294
|
+
const importId = await api.storage.importTable(resolved, formData, options.selection);
|
|
3295
|
+
console.log(`Import started (ID: ${importId}). Waiting for completion ...`);
|
|
3296
|
+
const pollInterval = 1e3;
|
|
3297
|
+
const maxAttempts = 300;
|
|
3298
|
+
for (let i = 0; i < maxAttempts; i++) {
|
|
3299
|
+
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
3300
|
+
const imp = await api.storage.getImport(resolved, importId);
|
|
3301
|
+
if (imp.finished !== null) {
|
|
3302
|
+
if (imp.succeeded) {
|
|
3303
|
+
console.log(chalk14.green(`Import completed successfully (${imp.duration}ms).`));
|
|
3304
|
+
} else {
|
|
3305
|
+
console.error(chalk14.red(`Import failed: ${imp.error}`));
|
|
3306
|
+
process.exit(1);
|
|
3307
|
+
}
|
|
3308
|
+
return;
|
|
3309
|
+
}
|
|
3310
|
+
}
|
|
3311
|
+
console.error(chalk14.yellow("Import still in progress. Check status later."));
|
|
3312
|
+
} catch (error) {
|
|
3313
|
+
handleError(error);
|
|
3314
|
+
}
|
|
3315
|
+
});
|
|
3316
|
+
table.command("import-formats").description("List supported import formats").action(async (_options, cmd) => {
|
|
3317
|
+
try {
|
|
3318
|
+
const outputFormat = getOutputFormat6(cmd);
|
|
3319
|
+
const api = createApiClient();
|
|
3320
|
+
const response = await api.storage.getSupportedImportFormats();
|
|
3321
|
+
if (outputFormat === "json") {
|
|
3322
|
+
format(response, { format: outputFormat });
|
|
3323
|
+
return;
|
|
3324
|
+
}
|
|
3325
|
+
const rows = response.formats.map((f) => ({
|
|
3326
|
+
id: f.id,
|
|
3327
|
+
displayName: f.displayName,
|
|
3328
|
+
category: f.category,
|
|
3329
|
+
extensions: f.extensions.join(", "),
|
|
3330
|
+
mimeTypes: f.mimeTypes.join(", "),
|
|
3331
|
+
multiTable: f.multiTable ? "yes" : "no",
|
|
3332
|
+
userDefined: f.userDefined ? "yes" : "no"
|
|
3333
|
+
}));
|
|
3334
|
+
format(rows, { format: outputFormat, columns: ["id", "displayName", "category", "extensions", "mimeTypes", "multiTable", "userDefined"] });
|
|
3335
|
+
} catch (error) {
|
|
3336
|
+
handleError(error);
|
|
3337
|
+
}
|
|
3338
|
+
});
|
|
3339
|
+
table.command("export").description("Export table data in any supported format (see `table export-formats`)").argument("<ref>", "Table entity reference").argument("<format>", "Export format (csv, tsv, excel, parquet, arrow, orc, avro, json, jsonl, yaml, xml, html, pdf, sqlite, duckdb, hdf5, netcdf, ...)").option("--out <file>", "Output file").option("--compression <algorithm>", "Compression wrapper: gzip, bzip2, xz, or zstd").option("--archive <algorithm>", "Archive wrapper: zip or tar").option("--rows <range>", "Row range (e.g., 0:1000) \u2014 half-open").option("--cols <range>", "Column range (e.g., 0:5) \u2014 half-open").option("--delimiter <char>", "CSV/TSV only: single-character delimiter override").option("--quote <char>", 'CSV/TSV only: quote character (use "" for empty)').option("--null <token>", 'CSV/TSV only: null token (default "?")').option("--no-quote-all", "CSV/TSV only: only quote fields when necessary (default quotes every field)").option("--async", "Queue an async export (with progress + later re-download) instead of streaming directly to disk", false).action(async (ref, fmt, options, cmd) => {
|
|
3340
|
+
try {
|
|
3341
|
+
const overrides = getOverrides6(cmd);
|
|
3342
|
+
const resolved = parseEntityReference(ref, overrides);
|
|
3343
|
+
const api = createApiClient();
|
|
3344
|
+
const formats = await api.storage.getSupportedExportFormats();
|
|
3345
|
+
const format2 = formats.formats.find((f) => f.id.toLowerCase() === fmt.toLowerCase());
|
|
3346
|
+
if (!format2) {
|
|
3347
|
+
console.error(chalk14.red(`Unknown format: "${fmt}". Run \`diafunc table export-formats\` to see the catalogue.`));
|
|
3348
|
+
process.exit(1);
|
|
3349
|
+
}
|
|
3350
|
+
if (options.compression && !formats.compressionAlgorithms.includes(options.compression)) {
|
|
3351
|
+
console.error(chalk14.red(`Unknown compression: "${options.compression}". Use one of ${formats.compressionAlgorithms.join(", ")}.`));
|
|
3352
|
+
process.exit(1);
|
|
3353
|
+
}
|
|
3354
|
+
if (options.archive && !formats.archiveAlgorithms.includes(options.archive)) {
|
|
3355
|
+
console.error(chalk14.red(`Unknown archive: "${options.archive}". Use one of ${formats.archiveAlgorithms.join(", ")}.`));
|
|
3356
|
+
process.exit(1);
|
|
3357
|
+
}
|
|
3358
|
+
const exportOptions = {
|
|
3359
|
+
compression: options.compression,
|
|
3360
|
+
archive: options.archive
|
|
3361
|
+
};
|
|
3362
|
+
if (options.rows) {
|
|
3363
|
+
const [from, to] = String(options.rows).split(":").map(Number);
|
|
3364
|
+
if (!isNaN(from)) exportOptions.fromRow = from;
|
|
3365
|
+
if (!isNaN(to)) exportOptions.toRow = to;
|
|
3366
|
+
}
|
|
3367
|
+
if (options.cols) {
|
|
3368
|
+
const [from, to] = String(options.cols).split(":").map(Number);
|
|
3369
|
+
if (!isNaN(from)) exportOptions.fromColumn = from;
|
|
3370
|
+
if (!isNaN(to)) exportOptions.toColumn = to;
|
|
3371
|
+
}
|
|
3372
|
+
const csvLike = format2.id === "csv" || format2.id === "tsv";
|
|
3373
|
+
if (csvLike) {
|
|
3374
|
+
if (options.delimiter !== void 0) exportOptions.delimiter = options.delimiter;
|
|
3375
|
+
if (options.quote !== void 0) exportOptions.quote = options.quote;
|
|
3376
|
+
if (options.null !== void 0) exportOptions.nullValue = options.null;
|
|
3377
|
+
if (options.quoteAll === false) exportOptions.quoteAll = false;
|
|
3378
|
+
}
|
|
3379
|
+
const useStream = !options.async;
|
|
3380
|
+
if (useStream) {
|
|
3381
|
+
const response = await api.storage.streamExport(resolved, format2.id, exportOptions);
|
|
3382
|
+
const outFile = options.out ?? deriveOutFile(resolved.entityId, format2.extension, options.archive, options.compression);
|
|
3383
|
+
const buffer = Buffer.from(await response.arrayBuffer());
|
|
3384
|
+
fs4.writeFileSync(outFile, buffer);
|
|
3385
|
+
console.log(chalk14.green(`Table streamed to ${outFile}`));
|
|
3386
|
+
} else {
|
|
3387
|
+
const exportId = await api.storage.exportTable(resolved, format2.id, exportOptions);
|
|
3388
|
+
console.log(chalk14.green(`Export queued (ID: ${exportId}).`));
|
|
3389
|
+
console.log(`Poll progress: diafunc table exports get ${exportId} --ref ${ref}`);
|
|
3390
|
+
}
|
|
3391
|
+
} catch (error) {
|
|
3392
|
+
handleError(error);
|
|
3393
|
+
}
|
|
3394
|
+
});
|
|
3395
|
+
table.command("export-formats").description("List supported export formats").action(async (_options, cmd) => {
|
|
3396
|
+
try {
|
|
3397
|
+
const outputFormat = getOutputFormat6(cmd);
|
|
3398
|
+
const api = createApiClient();
|
|
3399
|
+
const response = await api.storage.getSupportedExportFormats();
|
|
3400
|
+
if (outputFormat === "json") {
|
|
3401
|
+
format(response, { format: outputFormat });
|
|
3402
|
+
return;
|
|
3403
|
+
}
|
|
3404
|
+
const rows = response.formats.map((f) => ({
|
|
3405
|
+
id: f.id,
|
|
3406
|
+
displayName: f.displayName,
|
|
3407
|
+
category: f.category,
|
|
3408
|
+
extension: f.extension,
|
|
3409
|
+
mimeType: f.mimeType,
|
|
3410
|
+
knownLimitations: f.knownLimitations.join(" / ")
|
|
3411
|
+
}));
|
|
3412
|
+
format(rows, { format: outputFormat, columns: ["id", "displayName", "category", "extension", "mimeType", "knownLimitations"] });
|
|
3413
|
+
console.log(chalk14.dim(`Compression: ${response.compressionAlgorithms.join(", ")}`));
|
|
3414
|
+
console.log(chalk14.dim(`Archive: ${response.archiveAlgorithms.join(", ")}`));
|
|
3415
|
+
} catch (error) {
|
|
3416
|
+
handleError(error);
|
|
3417
|
+
}
|
|
3418
|
+
});
|
|
3419
|
+
const row = table.command("row").description("Manage table rows");
|
|
3420
|
+
row.command("add").description("Append a row to a table").argument("<ref>", "Table entity reference").action(async (ref, _options, cmd) => {
|
|
2802
3421
|
try {
|
|
2803
|
-
const overrides =
|
|
3422
|
+
const overrides = getOverrides6(cmd);
|
|
2804
3423
|
const resolved = parseEntityReference(ref, overrides);
|
|
2805
|
-
if (!fs3.existsSync(file)) {
|
|
2806
|
-
console.error(chalk13.red(`File not found: ${file}`));
|
|
2807
|
-
process.exit(1);
|
|
2808
|
-
}
|
|
2809
3424
|
const api = createApiClient();
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
const formData = new FormData();
|
|
2813
|
-
formData.append("content", blob, path2.basename(file));
|
|
2814
|
-
const columnHeaders = options.columnHeaders !== false;
|
|
2815
|
-
console.log(`Importing ${path2.basename(file)} ...`);
|
|
2816
|
-
const importId = await api.storage.importTable(resolved, formData, columnHeaders);
|
|
2817
|
-
console.log(`Import started (ID: ${importId}). Waiting for completion ...`);
|
|
2818
|
-
const pollInterval = 1e3;
|
|
2819
|
-
const maxAttempts = 300;
|
|
2820
|
-
for (let i = 0; i < maxAttempts; i++) {
|
|
2821
|
-
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
2822
|
-
const imp = await api.storage.getImport(resolved, importId);
|
|
2823
|
-
if (imp.finished !== null) {
|
|
2824
|
-
if (imp.succeeded) {
|
|
2825
|
-
console.log(chalk13.green(`Import completed successfully (${imp.duration}ms).`));
|
|
2826
|
-
} else {
|
|
2827
|
-
console.error(chalk13.red(`Import failed: ${imp.error}`));
|
|
2828
|
-
process.exit(1);
|
|
2829
|
-
}
|
|
2830
|
-
return;
|
|
2831
|
-
}
|
|
2832
|
-
}
|
|
2833
|
-
console.error(chalk13.yellow("Import still in progress. Check status later."));
|
|
3425
|
+
await api.storage.appendRow(resolved);
|
|
3426
|
+
console.log(chalk14.green("Row appended."));
|
|
2834
3427
|
} catch (error) {
|
|
2835
3428
|
handleError(error);
|
|
2836
3429
|
}
|
|
2837
3430
|
});
|
|
2838
|
-
|
|
3431
|
+
row.command("insert").description("Insert an empty row at the given index, shifting existing rows down").argument("<ref>", "Table entity reference").argument("<index>", "Row index").action(async (ref, index, _options, cmd) => {
|
|
2839
3432
|
try {
|
|
2840
|
-
const overrides =
|
|
3433
|
+
const overrides = getOverrides6(cmd);
|
|
2841
3434
|
const resolved = parseEntityReference(ref, overrides);
|
|
2842
3435
|
const api = createApiClient();
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
if (fmt.toLowerCase() === "csv") {
|
|
2846
|
-
response = await api.storage.exportTableCsv(resolved);
|
|
2847
|
-
defaultExt = ".csv";
|
|
2848
|
-
} else if (fmt.toLowerCase() === "excel" || fmt.toLowerCase() === "xlsx") {
|
|
2849
|
-
response = await api.storage.exportTableExcel(resolved);
|
|
2850
|
-
defaultExt = ".xlsx";
|
|
2851
|
-
} else {
|
|
2852
|
-
console.error(chalk13.red(`Unknown format: "${fmt}". Use "csv" or "excel".`));
|
|
2853
|
-
process.exit(1);
|
|
2854
|
-
}
|
|
2855
|
-
const outFile = options.out ?? `${resolved.entityId}${defaultExt}`;
|
|
2856
|
-
const buffer = Buffer.from(await response.arrayBuffer());
|
|
2857
|
-
fs3.writeFileSync(outFile, buffer);
|
|
2858
|
-
console.log(chalk13.green(`Table exported to ${outFile}`));
|
|
3436
|
+
await api.storage.insertRow(resolved, parseInt(index, 10));
|
|
3437
|
+
console.log(chalk14.green(`Row inserted at index ${index}.`));
|
|
2859
3438
|
} catch (error) {
|
|
2860
3439
|
handleError(error);
|
|
2861
3440
|
}
|
|
2862
3441
|
});
|
|
2863
|
-
|
|
2864
|
-
row.command("add").description("Append a row to a table").argument("<ref>", "Table entity reference").action(async (ref, _options, cmd) => {
|
|
3442
|
+
row.command("remove").description("Remove a row in place (blanks the row; no shift)").argument("<ref>", "Table entity reference").argument("<index>", "Row index").action(async (ref, index, _options, cmd) => {
|
|
2865
3443
|
try {
|
|
2866
|
-
const overrides =
|
|
3444
|
+
const overrides = getOverrides6(cmd);
|
|
2867
3445
|
const resolved = parseEntityReference(ref, overrides);
|
|
2868
3446
|
const api = createApiClient();
|
|
2869
|
-
await api.storage.
|
|
2870
|
-
console.log(
|
|
3447
|
+
await api.storage.removeRow(resolved, parseInt(index, 10));
|
|
3448
|
+
console.log(chalk14.green(`Row ${index} removed.`));
|
|
2871
3449
|
} catch (error) {
|
|
2872
3450
|
handleError(error);
|
|
2873
3451
|
}
|
|
2874
3452
|
});
|
|
2875
|
-
row.command("
|
|
3453
|
+
row.command("delete").description("Delete a row and shift the rows below up by one").argument("<ref>", "Table entity reference").argument("<index>", "Row index").action(async (ref, index, _options, cmd) => {
|
|
2876
3454
|
try {
|
|
2877
|
-
const overrides =
|
|
3455
|
+
const overrides = getOverrides6(cmd);
|
|
2878
3456
|
const resolved = parseEntityReference(ref, overrides);
|
|
2879
3457
|
const api = createApiClient();
|
|
2880
3458
|
await api.storage.deleteRow(resolved, parseInt(index, 10));
|
|
2881
|
-
console.log(
|
|
3459
|
+
console.log(chalk14.green(`Row ${index} deleted.`));
|
|
2882
3460
|
} catch (error) {
|
|
2883
3461
|
handleError(error);
|
|
2884
3462
|
}
|
|
@@ -2886,22 +3464,44 @@ function registerTableCommands(program) {
|
|
|
2886
3464
|
const column = table.command("column").description("Manage table columns");
|
|
2887
3465
|
column.command("add").description("Append a column to a table").argument("<ref>", "Table entity reference").action(async (ref, _options, cmd) => {
|
|
2888
3466
|
try {
|
|
2889
|
-
const overrides =
|
|
3467
|
+
const overrides = getOverrides6(cmd);
|
|
2890
3468
|
const resolved = parseEntityReference(ref, overrides);
|
|
2891
3469
|
const api = createApiClient();
|
|
2892
3470
|
await api.storage.appendColumn(resolved);
|
|
2893
|
-
console.log(
|
|
3471
|
+
console.log(chalk14.green("Column appended."));
|
|
2894
3472
|
} catch (error) {
|
|
2895
3473
|
handleError(error);
|
|
2896
3474
|
}
|
|
2897
3475
|
});
|
|
2898
|
-
column.command("
|
|
3476
|
+
column.command("insert").description("Insert an empty column at the given index, shifting existing columns right").argument("<ref>", "Table entity reference").argument("<index>", "Column index").action(async (ref, index, _options, cmd) => {
|
|
2899
3477
|
try {
|
|
2900
|
-
const overrides =
|
|
3478
|
+
const overrides = getOverrides6(cmd);
|
|
3479
|
+
const resolved = parseEntityReference(ref, overrides);
|
|
3480
|
+
const api = createApiClient();
|
|
3481
|
+
await api.storage.insertColumn(resolved, parseInt(index, 10));
|
|
3482
|
+
console.log(chalk14.green(`Column inserted at index ${index}.`));
|
|
3483
|
+
} catch (error) {
|
|
3484
|
+
handleError(error);
|
|
3485
|
+
}
|
|
3486
|
+
});
|
|
3487
|
+
column.command("remove").description("Remove a column in place (blanks the column; no shift)").argument("<ref>", "Table entity reference").argument("<index>", "Column index").action(async (ref, index, _options, cmd) => {
|
|
3488
|
+
try {
|
|
3489
|
+
const overrides = getOverrides6(cmd);
|
|
3490
|
+
const resolved = parseEntityReference(ref, overrides);
|
|
3491
|
+
const api = createApiClient();
|
|
3492
|
+
await api.storage.removeColumn(resolved, parseInt(index, 10));
|
|
3493
|
+
console.log(chalk14.green(`Column ${index} removed.`));
|
|
3494
|
+
} catch (error) {
|
|
3495
|
+
handleError(error);
|
|
3496
|
+
}
|
|
3497
|
+
});
|
|
3498
|
+
column.command("delete").description("Delete a column and shift the columns to its right left by one").argument("<ref>", "Table entity reference").argument("<index>", "Column index").action(async (ref, index, _options, cmd) => {
|
|
3499
|
+
try {
|
|
3500
|
+
const overrides = getOverrides6(cmd);
|
|
2901
3501
|
const resolved = parseEntityReference(ref, overrides);
|
|
2902
3502
|
const api = createApiClient();
|
|
2903
3503
|
await api.storage.deleteColumn(resolved, parseInt(index, 10));
|
|
2904
|
-
console.log(
|
|
3504
|
+
console.log(chalk14.green(`Column ${index} deleted.`));
|
|
2905
3505
|
} catch (error) {
|
|
2906
3506
|
handleError(error);
|
|
2907
3507
|
}
|
|
@@ -2909,7 +3509,7 @@ function registerTableCommands(program) {
|
|
|
2909
3509
|
const cell = table.command("cell").description("Manage table cells");
|
|
2910
3510
|
cell.command("set").description("Set a cell value").argument("<ref>", "Table entity reference").argument("<row>", "Row index").argument("<col>", "Column index").argument("<value>", "Cell value").action(async (ref, row2, col, value, _options, cmd) => {
|
|
2911
3511
|
try {
|
|
2912
|
-
const overrides =
|
|
3512
|
+
const overrides = getOverrides6(cmd);
|
|
2913
3513
|
const resolved = parseEntityReference(ref, overrides);
|
|
2914
3514
|
const api = createApiClient();
|
|
2915
3515
|
await api.storage.mergeCells(resolved, [{
|
|
@@ -2918,29 +3518,141 @@ function registerTableCommands(program) {
|
|
|
2918
3518
|
value,
|
|
2919
3519
|
type: "text"
|
|
2920
3520
|
}]);
|
|
2921
|
-
console.log(
|
|
3521
|
+
console.log(chalk14.green(`Cell [${row2}, ${col}] set to "${value}".`));
|
|
2922
3522
|
} catch (error) {
|
|
2923
3523
|
handleError(error);
|
|
2924
3524
|
}
|
|
2925
3525
|
});
|
|
2926
3526
|
cell.command("delete").description("Delete a cell value").argument("<ref>", "Table entity reference").argument("<row>", "Row index").argument("<col>", "Column index").action(async (ref, row2, col, _options, cmd) => {
|
|
2927
3527
|
try {
|
|
2928
|
-
const overrides =
|
|
3528
|
+
const overrides = getOverrides6(cmd);
|
|
2929
3529
|
const resolved = parseEntityReference(ref, overrides);
|
|
2930
3530
|
const api = createApiClient();
|
|
2931
|
-
await api.storage.
|
|
2932
|
-
console.log(
|
|
3531
|
+
await api.storage.removeCell(resolved, parseInt(row2, 10), parseInt(col, 10));
|
|
3532
|
+
console.log(chalk14.green(`Cell [${row2}, ${col}] deleted.`));
|
|
2933
3533
|
} catch (error) {
|
|
2934
3534
|
handleError(error);
|
|
2935
3535
|
}
|
|
2936
3536
|
});
|
|
2937
3537
|
table.command("clear").description("Clear all data from a table").argument("<ref>", "Table entity reference").action(async (ref, _options, cmd) => {
|
|
2938
3538
|
try {
|
|
2939
|
-
const overrides =
|
|
3539
|
+
const overrides = getOverrides6(cmd);
|
|
2940
3540
|
const resolved = parseEntityReference(ref, overrides);
|
|
2941
3541
|
const api = createApiClient();
|
|
2942
3542
|
await api.storage.clearTable(resolved);
|
|
2943
|
-
console.log(
|
|
3543
|
+
console.log(chalk14.green("Table cleared."));
|
|
3544
|
+
} catch (error) {
|
|
3545
|
+
handleError(error);
|
|
3546
|
+
}
|
|
3547
|
+
});
|
|
3548
|
+
}
|
|
3549
|
+
|
|
3550
|
+
// src/commands/notebook/index.ts
|
|
3551
|
+
import chalk15 from "chalk";
|
|
3552
|
+
import * as fs5 from "fs";
|
|
3553
|
+
import * as path4 from "path";
|
|
3554
|
+
function getOutputFormat7(cmd) {
|
|
3555
|
+
const config = loadConfig();
|
|
3556
|
+
const globalOpts = cmd.optsWithGlobals();
|
|
3557
|
+
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
3558
|
+
}
|
|
3559
|
+
function getOverrides7(cmd) {
|
|
3560
|
+
const opts = cmd.optsWithGlobals();
|
|
3561
|
+
return { project: opts.project, branch: opts.branch };
|
|
3562
|
+
}
|
|
3563
|
+
function registerNotebookCommands(program) {
|
|
3564
|
+
const notebook = program.command("notebook").description("Export and import notebook bundles");
|
|
3565
|
+
notebook.command("export").description("Export one or more notebooks (plus their closure) to a .dfnb bundle").argument("<project>", "Project reference (projectId or projectId/branch)").argument("<notebookIds...>", "Entity id(s) of the notebook(s) to export").option("--out <file>", "Output file (defaults to notebooks.dfnb)").option("--data <encoding>", "Embedded table-data encoding: csv (default) or parquet", "csv").option("--async", "Queue a background job instead of streaming the download now").action(async (project, notebookIds, options, cmd) => {
|
|
3566
|
+
try {
|
|
3567
|
+
const overrides = getOverrides7(cmd);
|
|
3568
|
+
const ref = parseProjectReference(project, overrides);
|
|
3569
|
+
const api = createApiClient();
|
|
3570
|
+
const request = { rootEntityIds: notebookIds, dataFormat: options.data };
|
|
3571
|
+
if (options.async) {
|
|
3572
|
+
const bundleId = await api.storage.exportBundle(ref.projectId, ref.projectBranch, request);
|
|
3573
|
+
console.log(chalk15.green(`Export queued (bundle ID: ${bundleId}).`));
|
|
3574
|
+
console.log(`Poll progress: diafunc notebook bundles ${project}`);
|
|
3575
|
+
return;
|
|
3576
|
+
}
|
|
3577
|
+
const response = await api.storage.streamBundle(ref.projectId, ref.projectBranch, request);
|
|
3578
|
+
const outFile = options.out ?? "notebooks.dfnb";
|
|
3579
|
+
const buffer = Buffer.from(await response.arrayBuffer());
|
|
3580
|
+
fs5.writeFileSync(outFile, buffer);
|
|
3581
|
+
console.log(chalk15.green(`Bundle written to ${outFile} (${buffer.length} bytes, ${notebookIds.length} notebook(s)).`));
|
|
3582
|
+
} catch (error) {
|
|
3583
|
+
handleError(error);
|
|
3584
|
+
}
|
|
3585
|
+
});
|
|
3586
|
+
notebook.command("import").description("Import a .dfnb bundle into a project").argument("<project>", "Target project reference (projectId or projectId/branch)").argument("<file>", "Path to the .dfnb bundle").option("--on-conflict <policy>", "copy (default), overwrite, or skip", "copy").option("--preview", "Show the bundle inventory without importing").action(async (project, file, options, cmd) => {
|
|
3587
|
+
try {
|
|
3588
|
+
const outputFormat = getOutputFormat7(cmd);
|
|
3589
|
+
const overrides = getOverrides7(cmd);
|
|
3590
|
+
const ref = parseProjectReference(project, overrides);
|
|
3591
|
+
const api = createApiClient();
|
|
3592
|
+
const fileBuffer = fs5.readFileSync(file);
|
|
3593
|
+
const blob = new Blob([fileBuffer]);
|
|
3594
|
+
const formData = new FormData();
|
|
3595
|
+
formData.append("content", blob, path4.basename(file));
|
|
3596
|
+
if (options.preview) {
|
|
3597
|
+
const preview = await api.storage.previewBundleImport(ref.projectId, ref.projectBranch, formData);
|
|
3598
|
+
if (outputFormat === "json") {
|
|
3599
|
+
format(preview, { format: outputFormat });
|
|
3600
|
+
return;
|
|
3601
|
+
}
|
|
3602
|
+
console.log(chalk15.bold(`${preview.kind} bundle \xB7 ${preview.entityCount} entities`));
|
|
3603
|
+
if (preview.sourceProjectId) {
|
|
3604
|
+
console.log(chalk15.dim(`from ${preview.sourceProjectId}/${preview.sourceProjectBranch}` + (preview.createdBy ? ` \xB7 by ${preview.createdBy}` : "")));
|
|
3605
|
+
}
|
|
3606
|
+
const counts = /* @__PURE__ */ new Map();
|
|
3607
|
+
for (const e of preview.entities ?? []) {
|
|
3608
|
+
counts.set(e.type, (counts.get(e.type) ?? 0) + 1);
|
|
3609
|
+
}
|
|
3610
|
+
for (const [type, count] of [...counts.entries()].sort((a, b) => a[0].localeCompare(b[0]))) {
|
|
3611
|
+
console.log(` ${type}: ${count}`);
|
|
3612
|
+
}
|
|
3613
|
+
if (preview.lossinessNotes && preview.lossinessNotes.length > 0) {
|
|
3614
|
+
console.log(chalk15.yellow("Lossiness:"));
|
|
3615
|
+
for (const note of preview.lossinessNotes) {
|
|
3616
|
+
console.log(chalk15.yellow(` - ${note}`));
|
|
3617
|
+
}
|
|
3618
|
+
}
|
|
3619
|
+
return;
|
|
3620
|
+
}
|
|
3621
|
+
const result = await api.storage.importBundle(ref.projectId, ref.projectBranch, formData, options.onConflict);
|
|
3622
|
+
if (outputFormat === "json") {
|
|
3623
|
+
format(result, { format: outputFormat });
|
|
3624
|
+
return;
|
|
3625
|
+
}
|
|
3626
|
+
console.log(chalk15.green(`Imported ${result.entityCount} entities, ${result.linkCount} links.`));
|
|
3627
|
+
console.log(`Notebook id(s): ${result.rootEntityIds.join(", ")}`);
|
|
3628
|
+
} catch (error) {
|
|
3629
|
+
handleError(error);
|
|
3630
|
+
}
|
|
3631
|
+
});
|
|
3632
|
+
notebook.command("bundles").description("List notebook-bundle export jobs for a project").argument("<project>", "Project reference (projectId or projectId/branch)").action(async (project, _options, cmd) => {
|
|
3633
|
+
try {
|
|
3634
|
+
const outputFormat = getOutputFormat7(cmd);
|
|
3635
|
+
const overrides = getOverrides7(cmd);
|
|
3636
|
+
const ref = parseProjectReference(project, overrides);
|
|
3637
|
+
const api = createApiClient();
|
|
3638
|
+
const bundles = await api.storage.getBundles(ref.projectId, ref.projectBranch);
|
|
3639
|
+
if (outputFormat === "json") {
|
|
3640
|
+
format(bundles, { format: outputFormat });
|
|
3641
|
+
return;
|
|
3642
|
+
}
|
|
3643
|
+
const rows = bundles.map((b) => ({
|
|
3644
|
+
bundleId: b.bundleId,
|
|
3645
|
+
kind: b.kind,
|
|
3646
|
+
filename: b.filename,
|
|
3647
|
+
entities: b.entityCount ?? "",
|
|
3648
|
+
progress: b.progress,
|
|
3649
|
+
succeeded: b.succeeded ?? "",
|
|
3650
|
+
error: b.error ?? ""
|
|
3651
|
+
}));
|
|
3652
|
+
format(rows, {
|
|
3653
|
+
format: outputFormat,
|
|
3654
|
+
columns: ["bundleId", "kind", "filename", "entities", "progress", "succeeded", "error"]
|
|
3655
|
+
});
|
|
2944
3656
|
} catch (error) {
|
|
2945
3657
|
handleError(error);
|
|
2946
3658
|
}
|
|
@@ -2948,10 +3660,10 @@ function registerTableCommands(program) {
|
|
|
2948
3660
|
}
|
|
2949
3661
|
|
|
2950
3662
|
// src/commands/function/index.ts
|
|
2951
|
-
import
|
|
2952
|
-
import * as
|
|
3663
|
+
import chalk16 from "chalk";
|
|
3664
|
+
import * as fs6 from "fs";
|
|
2953
3665
|
import * as os2 from "os";
|
|
2954
|
-
import * as
|
|
3666
|
+
import * as path5 from "path";
|
|
2955
3667
|
import { spawn } from "child_process";
|
|
2956
3668
|
import { randomUUID } from "crypto";
|
|
2957
3669
|
|
|
@@ -3004,12 +3716,12 @@ function buildFunctionEntity(args) {
|
|
|
3004
3716
|
}
|
|
3005
3717
|
|
|
3006
3718
|
// src/commands/function/index.ts
|
|
3007
|
-
function
|
|
3719
|
+
function getOutputFormat8(cmd) {
|
|
3008
3720
|
const config = loadConfig();
|
|
3009
3721
|
const globalOpts = cmd.optsWithGlobals();
|
|
3010
3722
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
3011
3723
|
}
|
|
3012
|
-
function
|
|
3724
|
+
function getOverrides8(cmd) {
|
|
3013
3725
|
const opts = cmd.optsWithGlobals();
|
|
3014
3726
|
return { project: opts.project, branch: opts.branch };
|
|
3015
3727
|
}
|
|
@@ -3027,8 +3739,8 @@ function registerFunctionCommands(program) {
|
|
|
3027
3739
|
const fn = program.command("function").description("Execute and manage functions");
|
|
3028
3740
|
fn.command("call").description("Execute a function").argument("<ref>", "Function entity reference").option("--async", "Execute asynchronously").option("--args <json>", "Arguments as JSON object").option("--target <ref>", "Target entity reference").action(async (ref, options, cmd) => {
|
|
3029
3741
|
try {
|
|
3030
|
-
const outputFormat =
|
|
3031
|
-
const overrides =
|
|
3742
|
+
const outputFormat = getOutputFormat8(cmd);
|
|
3743
|
+
const overrides = getOverrides8(cmd);
|
|
3032
3744
|
const resolved = parseEntityReference(ref, overrides);
|
|
3033
3745
|
const api = createApiClient();
|
|
3034
3746
|
const time = createTimeUuid();
|
|
@@ -3070,7 +3782,7 @@ function registerFunctionCommands(program) {
|
|
|
3070
3782
|
}, isAsync);
|
|
3071
3783
|
if (isAsync) {
|
|
3072
3784
|
if (outputFormat === "human") {
|
|
3073
|
-
console.log(
|
|
3785
|
+
console.log(chalk16.green("Function launched."));
|
|
3074
3786
|
console.log(` Evaluation ID: ${result.evaluationId}`);
|
|
3075
3787
|
} else {
|
|
3076
3788
|
format({ evaluationId: result.evaluationId }, { format: outputFormat });
|
|
@@ -3078,14 +3790,14 @@ function registerFunctionCommands(program) {
|
|
|
3078
3790
|
} else {
|
|
3079
3791
|
if (outputFormat === "human") {
|
|
3080
3792
|
if (result.successful) {
|
|
3081
|
-
console.log(
|
|
3793
|
+
console.log(chalk16.green("Function completed successfully."));
|
|
3082
3794
|
if (result.result) {
|
|
3083
3795
|
console.log(` Result: ${result.result}`);
|
|
3084
3796
|
}
|
|
3085
3797
|
const duration = result.completed - result.started;
|
|
3086
3798
|
console.log(` Duration: ${duration}ms`);
|
|
3087
3799
|
} else {
|
|
3088
|
-
console.log(
|
|
3800
|
+
console.log(chalk16.red("Function failed."));
|
|
3089
3801
|
console.log(` Error: ${result.error}`);
|
|
3090
3802
|
if (result.lineNumber > 0) {
|
|
3091
3803
|
console.log(` Line: ${result.lineNumber}, Column: ${result.columnNumber}`);
|
|
@@ -3093,7 +3805,7 @@ function registerFunctionCommands(program) {
|
|
|
3093
3805
|
}
|
|
3094
3806
|
if (result.outputs?.length) {
|
|
3095
3807
|
console.log();
|
|
3096
|
-
console.log(
|
|
3808
|
+
console.log(chalk16.bold("Outputs:"));
|
|
3097
3809
|
for (const out of result.outputs) {
|
|
3098
3810
|
console.log(` [${out.type}] ${out.output}`);
|
|
3099
3811
|
}
|
|
@@ -3108,8 +3820,8 @@ function registerFunctionCommands(program) {
|
|
|
3108
3820
|
});
|
|
3109
3821
|
fn.command("evaluations").description("List evaluations for a function").argument("<ref>", "Function entity reference").requiredOption("--date <date>", "Date and hour (YYYY-MM-DD-HH in UTC)").action(async (ref, options, cmd) => {
|
|
3110
3822
|
try {
|
|
3111
|
-
const outputFormat =
|
|
3112
|
-
const overrides =
|
|
3823
|
+
const outputFormat = getOutputFormat8(cmd);
|
|
3824
|
+
const overrides = getOverrides8(cmd);
|
|
3113
3825
|
const resolved = parseEntityReference(ref, overrides);
|
|
3114
3826
|
const api = createApiClient();
|
|
3115
3827
|
const parts = options.date.split("-").map(Number);
|
|
@@ -3142,16 +3854,16 @@ function registerFunctionCommands(program) {
|
|
|
3142
3854
|
});
|
|
3143
3855
|
fn.command("outputs").description("Get outputs for an evaluation").argument("<projectId>", "Project ID").argument("<evaluationId>", "Evaluation ID").action(async (projectId, evaluationId, _options, cmd) => {
|
|
3144
3856
|
try {
|
|
3145
|
-
const outputFormat =
|
|
3857
|
+
const outputFormat = getOutputFormat8(cmd);
|
|
3146
3858
|
const api = createApiClient();
|
|
3147
3859
|
const outputs = await api.evaluation.getOutputs(projectId, evaluationId);
|
|
3148
3860
|
if (outputFormat === "human") {
|
|
3149
3861
|
if (outputs.length === 0) {
|
|
3150
|
-
console.log(
|
|
3862
|
+
console.log(chalk16.dim("No outputs."));
|
|
3151
3863
|
}
|
|
3152
3864
|
for (const out of outputs) {
|
|
3153
3865
|
const time = new Date(out.timestamp).toISOString();
|
|
3154
|
-
console.log(`${
|
|
3866
|
+
console.log(`${chalk16.dim(time)} [${out.type}] ${out.output}`);
|
|
3155
3867
|
}
|
|
3156
3868
|
} else {
|
|
3157
3869
|
format(outputs, { format: outputFormat });
|
|
@@ -3162,8 +3874,8 @@ function registerFunctionCommands(program) {
|
|
|
3162
3874
|
});
|
|
3163
3875
|
fn.command("logs").description("Get logs for a function evaluation").argument("<ref>", "Function entity reference").requiredOption("--date <date>", "Date and hour (YYYY-MM-DD-HH in UTC)").action(async (ref, options, cmd) => {
|
|
3164
3876
|
try {
|
|
3165
|
-
const outputFormat =
|
|
3166
|
-
const overrides =
|
|
3877
|
+
const outputFormat = getOutputFormat8(cmd);
|
|
3878
|
+
const overrides = getOverrides8(cmd);
|
|
3167
3879
|
const resolved = parseEntityReference(ref, overrides);
|
|
3168
3880
|
const api = createApiClient();
|
|
3169
3881
|
const parts = options.date.split("-").map(Number);
|
|
@@ -3185,7 +3897,7 @@ function registerFunctionCommands(program) {
|
|
|
3185
3897
|
});
|
|
3186
3898
|
fn.command("stop").description("Stop a running evaluation").argument("<ref>", "Function entity reference").requiredOption("--date <date>", "Date and hour (YYYY-MM-DD-HH in UTC)").argument("<evaluationId>", "Evaluation ID").action(async (ref, evaluationId, options, cmd) => {
|
|
3187
3899
|
try {
|
|
3188
|
-
const overrides =
|
|
3900
|
+
const overrides = getOverrides8(cmd);
|
|
3189
3901
|
const resolved = parseEntityReference(ref, overrides);
|
|
3190
3902
|
const api = createApiClient();
|
|
3191
3903
|
const parts = options.date.split("-").map(Number);
|
|
@@ -3201,14 +3913,14 @@ function registerFunctionCommands(program) {
|
|
|
3201
3913
|
hour,
|
|
3202
3914
|
evaluationId
|
|
3203
3915
|
);
|
|
3204
|
-
console.log(
|
|
3916
|
+
console.log(chalk16.green(`Evaluation ${evaluationId} stopped.`));
|
|
3205
3917
|
} catch (error) {
|
|
3206
3918
|
handleError(error);
|
|
3207
3919
|
}
|
|
3208
3920
|
});
|
|
3209
3921
|
fn.command("engines").description("List available engines").action(async (_options, cmd) => {
|
|
3210
3922
|
try {
|
|
3211
|
-
const outputFormat =
|
|
3923
|
+
const outputFormat = getOutputFormat8(cmd);
|
|
3212
3924
|
const api = createApiClient();
|
|
3213
3925
|
const engines = await api.evaluation.getEngines();
|
|
3214
3926
|
format(engines, { format: outputFormat });
|
|
@@ -3218,8 +3930,8 @@ function registerFunctionCommands(program) {
|
|
|
3218
3930
|
});
|
|
3219
3931
|
fn.command("last-evaluation").description("Show the most recent evaluation of a function").argument("<ref>", "Function entity reference").action(async (ref, _options, cmd) => {
|
|
3220
3932
|
try {
|
|
3221
|
-
const outputFormat =
|
|
3222
|
-
const overrides =
|
|
3933
|
+
const outputFormat = getOutputFormat8(cmd);
|
|
3934
|
+
const overrides = getOverrides8(cmd);
|
|
3223
3935
|
const resolved = parseEntityReference(ref, overrides);
|
|
3224
3936
|
const api = createApiClient();
|
|
3225
3937
|
const evaluation = await api.evaluation.getLastEvaluation(
|
|
@@ -3235,10 +3947,10 @@ function registerFunctionCommands(program) {
|
|
|
3235
3947
|
});
|
|
3236
3948
|
fn.command("create").description("Create a new function entity").argument("<ref>", "Function entity reference").option("--language <lang>", "Function language (Java, JavaScript, Kotlin, Python, Scala)", "Java").option("--source <file>", "Initial source code file").option("--name <name>", "Display name (defaults to entityId)").action(async (ref, options, cmd) => {
|
|
3237
3949
|
try {
|
|
3238
|
-
const overrides =
|
|
3950
|
+
const overrides = getOverrides8(cmd);
|
|
3239
3951
|
const resolved = parseEntityReference(ref, overrides);
|
|
3240
3952
|
const api = createApiClient();
|
|
3241
|
-
const sourceCode = options.source ?
|
|
3953
|
+
const sourceCode = options.source ? fs6.readFileSync(options.source, "utf-8") : "";
|
|
3242
3954
|
const entity = buildFunctionEntity({
|
|
3243
3955
|
projectId: resolved.projectId,
|
|
3244
3956
|
projectBranch: resolved.projectBranch,
|
|
@@ -3249,7 +3961,7 @@ function registerFunctionCommands(program) {
|
|
|
3249
3961
|
sourceCode
|
|
3250
3962
|
});
|
|
3251
3963
|
await api.storage.saveEntities([entity]);
|
|
3252
|
-
console.log(
|
|
3964
|
+
console.log(chalk16.green(`Function "${resolved.entityId}" created (${options.language}).`));
|
|
3253
3965
|
} catch (error) {
|
|
3254
3966
|
handleError(error);
|
|
3255
3967
|
}
|
|
@@ -3257,14 +3969,14 @@ function registerFunctionCommands(program) {
|
|
|
3257
3969
|
const source = fn.command("source").description("Get or set function source code");
|
|
3258
3970
|
source.command("get").description("Print the function source code").argument("<ref>", "Function entity reference").option("--out <file>", "Write source to this file instead of stdout").action(async (ref, options, cmd) => {
|
|
3259
3971
|
try {
|
|
3260
|
-
const overrides =
|
|
3972
|
+
const overrides = getOverrides8(cmd);
|
|
3261
3973
|
const resolved = parseEntityReference(ref, overrides);
|
|
3262
3974
|
const api = createApiClient();
|
|
3263
3975
|
const entity = await api.storage.getEntity(resolved, true);
|
|
3264
3976
|
const sourceCode = decodeFunctionSource(entity);
|
|
3265
3977
|
if (options.out) {
|
|
3266
|
-
|
|
3267
|
-
console.log(
|
|
3978
|
+
fs6.writeFileSync(options.out, sourceCode);
|
|
3979
|
+
console.log(chalk16.green(`Source written to ${options.out}`));
|
|
3268
3980
|
} else {
|
|
3269
3981
|
process.stdout.write(sourceCode);
|
|
3270
3982
|
if (!sourceCode.endsWith("\n")) process.stdout.write("\n");
|
|
@@ -3275,10 +3987,10 @@ function registerFunctionCommands(program) {
|
|
|
3275
3987
|
});
|
|
3276
3988
|
source.command("set").description("Replace the function source code from a file or stdin").argument("<ref>", "Function entity reference").argument("[file]", "Source file; defaults to stdin").action(async (ref, file, _options, cmd) => {
|
|
3277
3989
|
try {
|
|
3278
|
-
const overrides =
|
|
3990
|
+
const overrides = getOverrides8(cmd);
|
|
3279
3991
|
const resolved = parseEntityReference(ref, overrides);
|
|
3280
3992
|
const api = createApiClient();
|
|
3281
|
-
const sourceCode = file ?
|
|
3993
|
+
const sourceCode = file ? fs6.readFileSync(file, "utf-8") : await new Promise((resolve, reject) => {
|
|
3282
3994
|
let data = "";
|
|
3283
3995
|
process.stdin.setEncoding("utf-8");
|
|
3284
3996
|
process.stdin.on("data", (chunk) => {
|
|
@@ -3288,36 +4000,36 @@ function registerFunctionCommands(program) {
|
|
|
3288
4000
|
process.stdin.on("error", reject);
|
|
3289
4001
|
});
|
|
3290
4002
|
await api.storage.saveEntityContentBase64(resolved, encodeFunctionSource(sourceCode));
|
|
3291
|
-
console.log(
|
|
4003
|
+
console.log(chalk16.green(`Source updated for "${resolved.entityId}".`));
|
|
3292
4004
|
} catch (error) {
|
|
3293
4005
|
handleError(error);
|
|
3294
4006
|
}
|
|
3295
4007
|
});
|
|
3296
4008
|
fn.command("edit").description("Open the function source in $EDITOR and save on exit").argument("<ref>", "Function entity reference").action(async (ref, _options, cmd) => {
|
|
3297
4009
|
try {
|
|
3298
|
-
const overrides =
|
|
4010
|
+
const overrides = getOverrides8(cmd);
|
|
3299
4011
|
const resolved = parseEntityReference(ref, overrides);
|
|
3300
4012
|
const api = createApiClient();
|
|
3301
4013
|
const entity = await api.storage.getEntity(resolved, true);
|
|
3302
4014
|
const currentSource = decodeFunctionSource(entity);
|
|
3303
4015
|
const language = entity.attributes?.["language"] ?? "txt";
|
|
3304
4016
|
const ext = extensionFor(language);
|
|
3305
|
-
const tmpFile =
|
|
3306
|
-
|
|
4017
|
+
const tmpFile = path5.join(os2.tmpdir(), `diafunc-${resolved.entityId}-${randomUUID()}.${ext}`);
|
|
4018
|
+
fs6.writeFileSync(tmpFile, currentSource);
|
|
3307
4019
|
const editor = process.env.VISUAL ?? process.env.EDITOR ?? "vi";
|
|
3308
4020
|
await new Promise((resolve, reject) => {
|
|
3309
4021
|
const child = spawn(editor, [tmpFile], { stdio: "inherit" });
|
|
3310
4022
|
child.on("exit", (code) => code === 0 ? resolve() : reject(new Error(`Editor exited with code ${code}`)));
|
|
3311
4023
|
child.on("error", reject);
|
|
3312
4024
|
});
|
|
3313
|
-
const newSource =
|
|
3314
|
-
|
|
4025
|
+
const newSource = fs6.readFileSync(tmpFile, "utf-8");
|
|
4026
|
+
fs6.unlinkSync(tmpFile);
|
|
3315
4027
|
if (newSource === currentSource) {
|
|
3316
|
-
console.log(
|
|
4028
|
+
console.log(chalk16.dim("No changes."));
|
|
3317
4029
|
return;
|
|
3318
4030
|
}
|
|
3319
4031
|
await api.storage.saveEntityContentBase64(resolved, encodeFunctionSource(newSource));
|
|
3320
|
-
console.log(
|
|
4032
|
+
console.log(chalk16.green(`Source updated for "${resolved.entityId}".`));
|
|
3321
4033
|
} catch (error) {
|
|
3322
4034
|
handleError(error);
|
|
3323
4035
|
}
|
|
@@ -3334,13 +4046,13 @@ function extensionFor(language) {
|
|
|
3334
4046
|
}
|
|
3335
4047
|
|
|
3336
4048
|
// src/commands/trigger/index.ts
|
|
3337
|
-
import
|
|
3338
|
-
function
|
|
4049
|
+
import chalk17 from "chalk";
|
|
4050
|
+
function getOutputFormat9(cmd) {
|
|
3339
4051
|
const config = loadConfig();
|
|
3340
4052
|
const globalOpts = cmd.optsWithGlobals();
|
|
3341
4053
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
3342
4054
|
}
|
|
3343
|
-
function
|
|
4055
|
+
function getOverrides9(cmd) {
|
|
3344
4056
|
const opts = cmd.optsWithGlobals();
|
|
3345
4057
|
return { project: opts.project, branch: opts.branch };
|
|
3346
4058
|
}
|
|
@@ -3348,8 +4060,8 @@ function registerTriggerCommands(program) {
|
|
|
3348
4060
|
const trigger = program.command("trigger").description("Manage function triggers");
|
|
3349
4061
|
trigger.command("list").description("List triggers for a function").argument("<ref>", "Function entity reference").action(async (ref, _options, cmd) => {
|
|
3350
4062
|
try {
|
|
3351
|
-
const outputFormat =
|
|
3352
|
-
const overrides =
|
|
4063
|
+
const outputFormat = getOutputFormat9(cmd);
|
|
4064
|
+
const overrides = getOverrides9(cmd);
|
|
3353
4065
|
const resolved = parseEntityReference(ref, overrides);
|
|
3354
4066
|
const api = createApiClient();
|
|
3355
4067
|
const triggers = await api.evaluation.getTriggers(
|
|
@@ -3376,8 +4088,8 @@ function registerTriggerCommands(program) {
|
|
|
3376
4088
|
});
|
|
3377
4089
|
trigger.command("get").description("Get a specific trigger").argument("<ref>", "Function entity reference").argument("<triggerId>", "Trigger ID").action(async (ref, triggerId, _options, cmd) => {
|
|
3378
4090
|
try {
|
|
3379
|
-
const outputFormat =
|
|
3380
|
-
const overrides =
|
|
4091
|
+
const outputFormat = getOutputFormat9(cmd);
|
|
4092
|
+
const overrides = getOverrides9(cmd);
|
|
3381
4093
|
const resolved = parseEntityReference(ref, overrides);
|
|
3382
4094
|
const api = createApiClient();
|
|
3383
4095
|
const t = await api.evaluation.getTrigger(
|
|
@@ -3394,7 +4106,7 @@ function registerTriggerCommands(program) {
|
|
|
3394
4106
|
});
|
|
3395
4107
|
trigger.command("delete").description("Delete a trigger").argument("<ref>", "Function entity reference").argument("<triggerId>", "Trigger ID").action(async (ref, triggerId, _options, cmd) => {
|
|
3396
4108
|
try {
|
|
3397
|
-
const overrides =
|
|
4109
|
+
const overrides = getOverrides9(cmd);
|
|
3398
4110
|
const resolved = parseEntityReference(ref, overrides);
|
|
3399
4111
|
const api = createApiClient();
|
|
3400
4112
|
await api.evaluation.deleteTrigger(
|
|
@@ -3404,14 +4116,14 @@ function registerTriggerCommands(program) {
|
|
|
3404
4116
|
resolved.entityBranch,
|
|
3405
4117
|
triggerId
|
|
3406
4118
|
);
|
|
3407
|
-
console.log(
|
|
4119
|
+
console.log(chalk17.green(`Trigger "${triggerId}" deleted.`));
|
|
3408
4120
|
} catch (error) {
|
|
3409
4121
|
handleError(error);
|
|
3410
4122
|
}
|
|
3411
4123
|
});
|
|
3412
4124
|
trigger.command("create").description("Create or update a trigger on a function").argument("<ref>", "Function entity reference").requiredOption("--type <type>", "Trigger type (SCHEDULE, EVENT, LINK, MANUAL)").option("--trigger-id <id>", "Trigger ID (auto-generated if omitted)").option("--expression <expr>", "Cron expression (for SCHEDULE) or event pattern").option("--origin <ref>", "Origin entity reference (for LINK/EVENT)").option("--persistent", "Persistent trigger (survives after first fire)").option("--inactive", "Create the trigger inactive").option("--max <n>", "Maximum fire count (0 = unlimited)", "0").option("--args <json>", "Arguments passed on fire (JSON object)").action(async (ref, options, cmd) => {
|
|
3413
4125
|
try {
|
|
3414
|
-
const overrides =
|
|
4126
|
+
const overrides = getOverrides9(cmd);
|
|
3415
4127
|
const fn = parseEntityReference(ref, overrides);
|
|
3416
4128
|
const api = createApiClient();
|
|
3417
4129
|
const args = options.args ? JSON.parse(options.args) : null;
|
|
@@ -3452,7 +4164,7 @@ function registerTriggerCommands(program) {
|
|
|
3452
4164
|
scheduler: null,
|
|
3453
4165
|
heartbeat: null
|
|
3454
4166
|
});
|
|
3455
|
-
console.log(
|
|
4167
|
+
console.log(chalk17.green("Trigger saved."));
|
|
3456
4168
|
} catch (error) {
|
|
3457
4169
|
handleError(error);
|
|
3458
4170
|
}
|
|
@@ -3460,14 +4172,14 @@ function registerTriggerCommands(program) {
|
|
|
3460
4172
|
}
|
|
3461
4173
|
|
|
3462
4174
|
// src/commands/schedule/index.ts
|
|
3463
|
-
import
|
|
4175
|
+
import chalk18 from "chalk";
|
|
3464
4176
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
3465
|
-
function
|
|
4177
|
+
function getOutputFormat10(cmd) {
|
|
3466
4178
|
const config = loadConfig();
|
|
3467
4179
|
const globalOpts = cmd.optsWithGlobals();
|
|
3468
4180
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
3469
4181
|
}
|
|
3470
|
-
function
|
|
4182
|
+
function getOverrides10(cmd) {
|
|
3471
4183
|
const opts = cmd.optsWithGlobals();
|
|
3472
4184
|
return { project: opts.project, branch: opts.branch };
|
|
3473
4185
|
}
|
|
@@ -3475,8 +4187,8 @@ function registerScheduleCommands(program) {
|
|
|
3475
4187
|
const schedule = program.command("schedule").description("Schedule function execution");
|
|
3476
4188
|
schedule.command("call").description("Schedule a function call").argument("<ref>", "Function entity reference").option("--args <json>", "Arguments as JSON object").option("--target <ref>", "Target entity reference").action(async (ref, options, cmd) => {
|
|
3477
4189
|
try {
|
|
3478
|
-
const outputFormat =
|
|
3479
|
-
const overrides =
|
|
4190
|
+
const outputFormat = getOutputFormat10(cmd);
|
|
4191
|
+
const overrides = getOverrides10(cmd);
|
|
3480
4192
|
const resolved = parseEntityReference(ref, overrides);
|
|
3481
4193
|
const api = createApiClient();
|
|
3482
4194
|
let args = null;
|
|
@@ -3512,7 +4224,7 @@ function registerScheduleCommands(program) {
|
|
|
3512
4224
|
removeFunction: false
|
|
3513
4225
|
});
|
|
3514
4226
|
if (outputFormat === "human") {
|
|
3515
|
-
console.log(
|
|
4227
|
+
console.log(chalk18.green("Function scheduled."));
|
|
3516
4228
|
} else {
|
|
3517
4229
|
format(result, { format: outputFormat });
|
|
3518
4230
|
}
|
|
@@ -3522,7 +4234,7 @@ function registerScheduleCommands(program) {
|
|
|
3522
4234
|
});
|
|
3523
4235
|
schedule.command("stop").description("Stop a scheduled function evaluation").argument("<ref>", "Function entity reference").argument("<evaluationId>", "Evaluation ID to stop").requiredOption("--date <date>", "Evaluation date/hour (YYYY-MM-DD-HH in UTC)").action(async (ref, evaluationId, options, cmd) => {
|
|
3524
4236
|
try {
|
|
3525
|
-
const overrides =
|
|
4237
|
+
const overrides = getOverrides10(cmd);
|
|
3526
4238
|
const resolved = parseEntityReference(ref, overrides);
|
|
3527
4239
|
const api = createApiClient();
|
|
3528
4240
|
const [year, month, day, hour] = options.date.split("-").map(Number);
|
|
@@ -3537,15 +4249,15 @@ function registerScheduleCommands(program) {
|
|
|
3537
4249
|
hour,
|
|
3538
4250
|
evaluationId
|
|
3539
4251
|
);
|
|
3540
|
-
console.log(
|
|
4252
|
+
console.log(chalk18.green(`Scheduled evaluation ${evaluationId} stopped.`));
|
|
3541
4253
|
} catch (error) {
|
|
3542
4254
|
handleError(error);
|
|
3543
4255
|
}
|
|
3544
4256
|
});
|
|
3545
4257
|
schedule.command("list").description("List persistent triggers (scheduled functions are modeled as triggers)").argument("<ref>", "Function entity reference").action(async (ref, _options, cmd) => {
|
|
3546
4258
|
try {
|
|
3547
|
-
const outputFormat =
|
|
3548
|
-
const overrides =
|
|
4259
|
+
const outputFormat = getOutputFormat10(cmd);
|
|
4260
|
+
const overrides = getOverrides10(cmd);
|
|
3549
4261
|
const resolved = parseEntityReference(ref, overrides);
|
|
3550
4262
|
const api = createApiClient();
|
|
3551
4263
|
const triggers = await api.evaluation.getTriggers(
|
|
@@ -3574,10 +4286,10 @@ function registerScheduleCommands(program) {
|
|
|
3574
4286
|
}
|
|
3575
4287
|
|
|
3576
4288
|
// src/commands/chat/index.ts
|
|
3577
|
-
import
|
|
3578
|
-
import * as
|
|
3579
|
-
import * as
|
|
3580
|
-
function
|
|
4289
|
+
import chalk19 from "chalk";
|
|
4290
|
+
import * as fs7 from "fs";
|
|
4291
|
+
import * as path6 from "path";
|
|
4292
|
+
function getOutputFormat11(cmd) {
|
|
3581
4293
|
const config = loadConfig();
|
|
3582
4294
|
const globalOpts = cmd.optsWithGlobals();
|
|
3583
4295
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -3615,7 +4327,7 @@ async function streamOneTurn(message, sessionId, projectId, branch) {
|
|
|
3615
4327
|
input = event.inputTokens;
|
|
3616
4328
|
output = event.outputTokens;
|
|
3617
4329
|
} else if (event.type === "error") {
|
|
3618
|
-
console.error(
|
|
4330
|
+
console.error(chalk19.red(`
|
|
3619
4331
|
Error: ${event.content}`));
|
|
3620
4332
|
}
|
|
3621
4333
|
} catch {
|
|
@@ -3626,19 +4338,19 @@ Error: ${event.content}`));
|
|
|
3626
4338
|
}
|
|
3627
4339
|
async function runChatRepl(options) {
|
|
3628
4340
|
const { input: promptInput } = await import("@inquirer/prompts");
|
|
3629
|
-
const { getUpdateNotice } = await import("./update-check-
|
|
4341
|
+
const { getUpdateNotice } = await import("./update-check-KL3CHODI.js");
|
|
3630
4342
|
let sessionId = options.session;
|
|
3631
|
-
console.log(
|
|
4343
|
+
console.log(chalk19.bold("Diafunc chat") + chalk19.dim(" \xB7 /help for commands, /quit to exit"));
|
|
3632
4344
|
if (sessionId) {
|
|
3633
|
-
console.log(
|
|
4345
|
+
console.log(chalk19.dim(`Continuing session ${sessionId}`));
|
|
3634
4346
|
}
|
|
3635
4347
|
const notice = await getUpdateNotice();
|
|
3636
|
-
if (notice) console.log(
|
|
4348
|
+
if (notice) console.log(chalk19.dim(notice));
|
|
3637
4349
|
console.log();
|
|
3638
4350
|
for (; ; ) {
|
|
3639
4351
|
let line;
|
|
3640
4352
|
try {
|
|
3641
|
-
line = await promptInput({ message:
|
|
4353
|
+
line = await promptInput({ message: chalk19.cyan.bold("you >") });
|
|
3642
4354
|
} catch {
|
|
3643
4355
|
console.log();
|
|
3644
4356
|
return;
|
|
@@ -3655,37 +4367,37 @@ async function runChatRepl(options) {
|
|
|
3655
4367
|
return;
|
|
3656
4368
|
case "new":
|
|
3657
4369
|
sessionId = void 0;
|
|
3658
|
-
console.log(
|
|
4370
|
+
console.log(chalk19.dim("Started a new session."));
|
|
3659
4371
|
continue;
|
|
3660
4372
|
case "session":
|
|
3661
4373
|
if (!arg) {
|
|
3662
|
-
console.log(
|
|
4374
|
+
console.log(chalk19.dim(`Current session: ${sessionId ?? "(new)"}`));
|
|
3663
4375
|
} else {
|
|
3664
4376
|
sessionId = arg;
|
|
3665
|
-
console.log(
|
|
4377
|
+
console.log(chalk19.dim(`Switched to session ${sessionId}`));
|
|
3666
4378
|
}
|
|
3667
4379
|
continue;
|
|
3668
4380
|
case "help":
|
|
3669
4381
|
case "h":
|
|
3670
4382
|
case "?":
|
|
3671
|
-
console.log(
|
|
3672
|
-
console.log(
|
|
3673
|
-
console.log(
|
|
4383
|
+
console.log(chalk19.dim(" /new start a new session"));
|
|
4384
|
+
console.log(chalk19.dim(" /session [id] switch to a session (no id = show current)"));
|
|
4385
|
+
console.log(chalk19.dim(" /quit exit the REPL"));
|
|
3674
4386
|
continue;
|
|
3675
4387
|
default:
|
|
3676
|
-
console.log(
|
|
4388
|
+
console.log(chalk19.dim(`Unknown command: /${cmd}. Try /help.`));
|
|
3677
4389
|
continue;
|
|
3678
4390
|
}
|
|
3679
4391
|
}
|
|
3680
|
-
process.stdout.write(
|
|
4392
|
+
process.stdout.write(chalk19.magenta.bold("diafunc > "));
|
|
3681
4393
|
try {
|
|
3682
4394
|
const result = await streamOneTurn(trimmed, sessionId, options.project, options.branch);
|
|
3683
4395
|
sessionId = result.sessionId || sessionId;
|
|
3684
4396
|
console.log();
|
|
3685
|
-
console.log(
|
|
4397
|
+
console.log(chalk19.dim(`[session ${sessionId} \xB7 ${result.input} in / ${result.output} out]`));
|
|
3686
4398
|
console.log();
|
|
3687
4399
|
} catch (error) {
|
|
3688
|
-
console.error(
|
|
4400
|
+
console.error(chalk19.red(`
|
|
3689
4401
|
Request failed: ${error.message}`));
|
|
3690
4402
|
}
|
|
3691
4403
|
}
|
|
@@ -3701,7 +4413,7 @@ function registerChatCommands(program) {
|
|
|
3701
4413
|
});
|
|
3702
4414
|
chat.command("send").description("Send a chat message (blocking)").argument("<message>", "Message to send").option("--project <id>", "Project context").option("--branch <branch>", "Project branch", "main").option("--session <id>", "Session ID to continue").action(async (message, options, cmd) => {
|
|
3703
4415
|
try {
|
|
3704
|
-
const outputFormat =
|
|
4416
|
+
const outputFormat = getOutputFormat11(cmd);
|
|
3705
4417
|
const api = createApiClient();
|
|
3706
4418
|
const response = await api.language.chat({
|
|
3707
4419
|
message,
|
|
@@ -3712,7 +4424,7 @@ function registerChatCommands(program) {
|
|
|
3712
4424
|
if (outputFormat === "human") {
|
|
3713
4425
|
console.log(response.content);
|
|
3714
4426
|
console.log();
|
|
3715
|
-
console.log(
|
|
4427
|
+
console.log(chalk19.dim(`Session: ${response.sessionId} | Tokens: ${response.inputTokens} in, ${response.outputTokens} out`));
|
|
3716
4428
|
} else {
|
|
3717
4429
|
format(response, { format: outputFormat });
|
|
3718
4430
|
}
|
|
@@ -3722,7 +4434,7 @@ function registerChatCommands(program) {
|
|
|
3722
4434
|
});
|
|
3723
4435
|
chat.command("stream").description("Send a chat message (streaming)").argument("<message>", "Message to send").option("--project <id>", "Project context").option("--branch <branch>", "Project branch", "main").option("--session <id>", "Session ID to continue").action(async (message, options, cmd) => {
|
|
3724
4436
|
try {
|
|
3725
|
-
const outputFormat =
|
|
4437
|
+
const outputFormat = getOutputFormat11(cmd);
|
|
3726
4438
|
const api = createApiClient();
|
|
3727
4439
|
const response = await api.language.chatStream({
|
|
3728
4440
|
message,
|
|
@@ -3777,9 +4489,9 @@ function registerChatCommands(program) {
|
|
|
3777
4489
|
sessionId = event.sessionId ?? "";
|
|
3778
4490
|
console.log();
|
|
3779
4491
|
console.log();
|
|
3780
|
-
console.log(
|
|
4492
|
+
console.log(chalk19.dim(`Session: ${sessionId} | Tokens: ${event.inputTokens} in, ${event.outputTokens} out`));
|
|
3781
4493
|
} else if (event.type === "error") {
|
|
3782
|
-
console.error(
|
|
4494
|
+
console.error(chalk19.red(`
|
|
3783
4495
|
Error: ${event.content}`));
|
|
3784
4496
|
}
|
|
3785
4497
|
} catch {
|
|
@@ -3794,17 +4506,17 @@ Error: ${event.content}`));
|
|
|
3794
4506
|
});
|
|
3795
4507
|
chat.command("upload").description("Upload a file for chat context").argument("<file>", "File to upload").action(async (file) => {
|
|
3796
4508
|
try {
|
|
3797
|
-
if (!
|
|
3798
|
-
console.error(
|
|
4509
|
+
if (!fs7.existsSync(file)) {
|
|
4510
|
+
console.error(chalk19.red(`File not found: ${file}`));
|
|
3799
4511
|
process.exit(1);
|
|
3800
4512
|
}
|
|
3801
4513
|
const api = createApiClient();
|
|
3802
|
-
const fileBuffer =
|
|
4514
|
+
const fileBuffer = fs7.readFileSync(file);
|
|
3803
4515
|
const blob = new Blob([fileBuffer]);
|
|
3804
4516
|
const formData = new FormData();
|
|
3805
|
-
formData.append("file", blob,
|
|
4517
|
+
formData.append("file", blob, path6.basename(file));
|
|
3806
4518
|
const result = await api.language.upload(formData);
|
|
3807
|
-
console.log(
|
|
4519
|
+
console.log(chalk19.green(`File uploaded: ${result}`));
|
|
3808
4520
|
} catch (error) {
|
|
3809
4521
|
handleError(error);
|
|
3810
4522
|
}
|
|
@@ -3812,7 +4524,7 @@ Error: ${event.content}`));
|
|
|
3812
4524
|
const session = chat.command("session").description("Manage chat sessions");
|
|
3813
4525
|
session.command("list").description("List chat sessions").action(async (_options, cmd) => {
|
|
3814
4526
|
try {
|
|
3815
|
-
const outputFormat =
|
|
4527
|
+
const outputFormat = getOutputFormat11(cmd);
|
|
3816
4528
|
const api = createApiClient();
|
|
3817
4529
|
const sessions = await api.language.getSessions();
|
|
3818
4530
|
format(sessions, {
|
|
@@ -3827,22 +4539,22 @@ Error: ${event.content}`));
|
|
|
3827
4539
|
try {
|
|
3828
4540
|
const api = createApiClient();
|
|
3829
4541
|
await api.language.deleteSession(sessionId);
|
|
3830
|
-
console.log(
|
|
4542
|
+
console.log(chalk19.green(`Session "${sessionId}" deleted.`));
|
|
3831
4543
|
} catch (error) {
|
|
3832
4544
|
handleError(error);
|
|
3833
4545
|
}
|
|
3834
4546
|
});
|
|
3835
4547
|
session.command("show").description("Show the message history of a chat session").argument("<sessionId>", "Session ID").action(async (sessionId, _options, cmd) => {
|
|
3836
4548
|
try {
|
|
3837
|
-
const outputFormat =
|
|
4549
|
+
const outputFormat = getOutputFormat11(cmd);
|
|
3838
4550
|
const api = createApiClient();
|
|
3839
4551
|
const detail = await api.language.getSession(sessionId);
|
|
3840
4552
|
if (outputFormat === "human") {
|
|
3841
|
-
console.log(
|
|
4553
|
+
console.log(chalk19.bold(detail.title) + chalk19.dim(` (${detail.sessionId})`));
|
|
3842
4554
|
console.log();
|
|
3843
4555
|
for (const msg of detail.messages) {
|
|
3844
|
-
const role = msg.role === "user" ?
|
|
3845
|
-
console.log(`${role} ${
|
|
4556
|
+
const role = msg.role === "user" ? chalk19.cyan.bold("You") : chalk19.magenta.bold("Diafunc");
|
|
4557
|
+
console.log(`${role} ${chalk19.dim(msg.created)}`);
|
|
3846
4558
|
console.log(msg.content);
|
|
3847
4559
|
console.log();
|
|
3848
4560
|
}
|
|
@@ -3857,14 +4569,14 @@ Error: ${event.content}`));
|
|
|
3857
4569
|
try {
|
|
3858
4570
|
const api = createApiClient();
|
|
3859
4571
|
await api.language.renameSession(sessionId, title);
|
|
3860
|
-
console.log(
|
|
4572
|
+
console.log(chalk19.green(`Session "${sessionId}" renamed to "${title}".`));
|
|
3861
4573
|
} catch (error) {
|
|
3862
4574
|
handleError(error);
|
|
3863
4575
|
}
|
|
3864
4576
|
});
|
|
3865
4577
|
chat.command("usage").description("Show token usage").action(async (_options, cmd) => {
|
|
3866
4578
|
try {
|
|
3867
|
-
const outputFormat =
|
|
4579
|
+
const outputFormat = getOutputFormat11(cmd);
|
|
3868
4580
|
const api = createApiClient();
|
|
3869
4581
|
const usage = await api.language.getUsage();
|
|
3870
4582
|
format(usage, { format: outputFormat });
|
|
@@ -3875,7 +4587,7 @@ Error: ${event.content}`));
|
|
|
3875
4587
|
}
|
|
3876
4588
|
|
|
3877
4589
|
// src/commands/search/index.ts
|
|
3878
|
-
function
|
|
4590
|
+
function getOutputFormat12(cmd) {
|
|
3879
4591
|
const config = loadConfig();
|
|
3880
4592
|
const globalOpts = cmd.optsWithGlobals();
|
|
3881
4593
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -3883,7 +4595,7 @@ function getOutputFormat11(cmd) {
|
|
|
3883
4595
|
function registerSearchCommands(program) {
|
|
3884
4596
|
program.command("search").description("Search entities across projects").argument("<query>", "Search query").option("--project <id>", "Limit search to a project").option("--branch <branch>", "Project branch", "main").action(async (query, options, cmd) => {
|
|
3885
4597
|
try {
|
|
3886
|
-
const outputFormat =
|
|
4598
|
+
const outputFormat = getOutputFormat12(cmd);
|
|
3887
4599
|
const api = createApiClient();
|
|
3888
4600
|
if (options.project) {
|
|
3889
4601
|
const results = await api.storage.searchProject(
|
|
@@ -3914,8 +4626,8 @@ function registerSearchCommands(program) {
|
|
|
3914
4626
|
}
|
|
3915
4627
|
|
|
3916
4628
|
// src/commands/group/index.ts
|
|
3917
|
-
import
|
|
3918
|
-
function
|
|
4629
|
+
import chalk20 from "chalk";
|
|
4630
|
+
function getOutputFormat13(cmd) {
|
|
3919
4631
|
const config = loadConfig();
|
|
3920
4632
|
const globalOpts = cmd.optsWithGlobals();
|
|
3921
4633
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -3924,7 +4636,7 @@ function registerGroupCommands(program) {
|
|
|
3924
4636
|
const group = program.command("group").description("Manage groups");
|
|
3925
4637
|
group.command("list").description("List groups").option("--all", "List all groups (admin)").action(async (options, cmd) => {
|
|
3926
4638
|
try {
|
|
3927
|
-
const outputFormat =
|
|
4639
|
+
const outputFormat = getOutputFormat13(cmd);
|
|
3928
4640
|
const api = createApiClient();
|
|
3929
4641
|
const groups = options.all ? await api.admin.getAllGroups() : await api.admin.getGroups();
|
|
3930
4642
|
format(groups, { format: outputFormat, columns: ["groupId", "name"] });
|
|
@@ -3934,7 +4646,7 @@ function registerGroupCommands(program) {
|
|
|
3934
4646
|
});
|
|
3935
4647
|
group.command("get").description("Get group details").argument("<groupId>", "Group ID").action(async (groupId, _options, cmd) => {
|
|
3936
4648
|
try {
|
|
3937
|
-
const outputFormat =
|
|
4649
|
+
const outputFormat = getOutputFormat13(cmd);
|
|
3938
4650
|
const api = createApiClient();
|
|
3939
4651
|
const g = await api.admin.getGroup(groupId);
|
|
3940
4652
|
format(g, { format: outputFormat });
|
|
@@ -3946,7 +4658,7 @@ function registerGroupCommands(program) {
|
|
|
3946
4658
|
try {
|
|
3947
4659
|
const api = createApiClient();
|
|
3948
4660
|
await api.admin.createGroup({ groupId, name: options.name ?? groupId });
|
|
3949
|
-
console.log(
|
|
4661
|
+
console.log(chalk20.green(`Group "${groupId}" created.`));
|
|
3950
4662
|
} catch (error) {
|
|
3951
4663
|
handleError(error);
|
|
3952
4664
|
}
|
|
@@ -3955,7 +4667,7 @@ function registerGroupCommands(program) {
|
|
|
3955
4667
|
try {
|
|
3956
4668
|
const api = createApiClient();
|
|
3957
4669
|
await api.admin.updateGroup({ groupId, name: options.name });
|
|
3958
|
-
console.log(
|
|
4670
|
+
console.log(chalk20.green(`Group "${groupId}" updated.`));
|
|
3959
4671
|
} catch (error) {
|
|
3960
4672
|
handleError(error);
|
|
3961
4673
|
}
|
|
@@ -3964,7 +4676,7 @@ function registerGroupCommands(program) {
|
|
|
3964
4676
|
try {
|
|
3965
4677
|
const api = createApiClient();
|
|
3966
4678
|
await api.admin.deleteGroup(groupId);
|
|
3967
|
-
console.log(
|
|
4679
|
+
console.log(chalk20.green(`Group "${groupId}" deleted.`));
|
|
3968
4680
|
} catch (error) {
|
|
3969
4681
|
handleError(error);
|
|
3970
4682
|
}
|
|
@@ -3972,7 +4684,7 @@ function registerGroupCommands(program) {
|
|
|
3972
4684
|
const members = group.command("members").description("Manage group members");
|
|
3973
4685
|
members.command("list").description("List group members").argument("<groupId>", "Group ID").action(async (groupId, _options, cmd) => {
|
|
3974
4686
|
try {
|
|
3975
|
-
const outputFormat =
|
|
4687
|
+
const outputFormat = getOutputFormat13(cmd);
|
|
3976
4688
|
const api = createApiClient();
|
|
3977
4689
|
const memberList = await api.admin.getGroupMembers(groupId);
|
|
3978
4690
|
format(memberList, { format: outputFormat, columns: ["userId", "role", "joined"] });
|
|
@@ -3984,7 +4696,7 @@ function registerGroupCommands(program) {
|
|
|
3984
4696
|
try {
|
|
3985
4697
|
const api = createApiClient();
|
|
3986
4698
|
await api.admin.inviteGroupMember(groupId, userId, role.toUpperCase());
|
|
3987
|
-
console.log(
|
|
4699
|
+
console.log(chalk20.green(`Invited ${userId} to group "${groupId}" as ${role.toUpperCase()}.`));
|
|
3988
4700
|
} catch (error) {
|
|
3989
4701
|
handleError(error);
|
|
3990
4702
|
}
|
|
@@ -3993,7 +4705,7 @@ function registerGroupCommands(program) {
|
|
|
3993
4705
|
try {
|
|
3994
4706
|
const api = createApiClient();
|
|
3995
4707
|
await api.admin.removeGroupMember(groupId, userId);
|
|
3996
|
-
console.log(
|
|
4708
|
+
console.log(chalk20.green(`Removed ${userId} from group "${groupId}".`));
|
|
3997
4709
|
} catch (error) {
|
|
3998
4710
|
handleError(error);
|
|
3999
4711
|
}
|
|
@@ -4001,7 +4713,7 @@ function registerGroupCommands(program) {
|
|
|
4001
4713
|
const projects = group.command("projects").description("Manage group projects");
|
|
4002
4714
|
projects.command("list").description("List group projects").argument("<groupId>", "Group ID").action(async (groupId, _options, cmd) => {
|
|
4003
4715
|
try {
|
|
4004
|
-
const outputFormat =
|
|
4716
|
+
const outputFormat = getOutputFormat13(cmd);
|
|
4005
4717
|
const api = createApiClient();
|
|
4006
4718
|
const projectList = await api.admin.getGroupProjects(groupId);
|
|
4007
4719
|
format(projectList, { format: outputFormat, columns: ["projectId", "visibility", "language"] });
|
|
@@ -4013,7 +4725,7 @@ function registerGroupCommands(program) {
|
|
|
4013
4725
|
try {
|
|
4014
4726
|
const api = createApiClient();
|
|
4015
4727
|
await api.admin.addGroupProject(groupId, projectId);
|
|
4016
|
-
console.log(
|
|
4728
|
+
console.log(chalk20.green(`Project "${projectId}" added to group "${groupId}".`));
|
|
4017
4729
|
} catch (error) {
|
|
4018
4730
|
handleError(error);
|
|
4019
4731
|
}
|
|
@@ -4022,7 +4734,7 @@ function registerGroupCommands(program) {
|
|
|
4022
4734
|
try {
|
|
4023
4735
|
const api = createApiClient();
|
|
4024
4736
|
await api.admin.removeGroupProject(groupId, projectId);
|
|
4025
|
-
console.log(
|
|
4737
|
+
console.log(chalk20.green(`Project "${projectId}" removed from group "${groupId}".`));
|
|
4026
4738
|
} catch (error) {
|
|
4027
4739
|
handleError(error);
|
|
4028
4740
|
}
|
|
@@ -4030,8 +4742,8 @@ function registerGroupCommands(program) {
|
|
|
4030
4742
|
}
|
|
4031
4743
|
|
|
4032
4744
|
// src/commands/admin/index.ts
|
|
4033
|
-
import
|
|
4034
|
-
function
|
|
4745
|
+
import chalk21 from "chalk";
|
|
4746
|
+
function getOutputFormat14(cmd) {
|
|
4035
4747
|
const config = loadConfig();
|
|
4036
4748
|
const globalOpts = cmd.optsWithGlobals();
|
|
4037
4749
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -4041,7 +4753,7 @@ function registerAdminCommands(program) {
|
|
|
4041
4753
|
const users = admin.command("users").description("Manage users");
|
|
4042
4754
|
users.command("list").description("List all users (admin)").action(async (_options, cmd) => {
|
|
4043
4755
|
try {
|
|
4044
|
-
const outputFormat =
|
|
4756
|
+
const outputFormat = getOutputFormat14(cmd);
|
|
4045
4757
|
const api = createApiClient();
|
|
4046
4758
|
const userList = await api.admin.getUsers();
|
|
4047
4759
|
const summary = userList.map((u) => ({
|
|
@@ -4061,7 +4773,7 @@ function registerAdminCommands(program) {
|
|
|
4061
4773
|
});
|
|
4062
4774
|
users.command("get").description("Get current user details").action(async (_options, cmd) => {
|
|
4063
4775
|
try {
|
|
4064
|
-
const outputFormat =
|
|
4776
|
+
const outputFormat = getOutputFormat14(cmd);
|
|
4065
4777
|
const api = createApiClient();
|
|
4066
4778
|
const user = await api.admin.getMyUser();
|
|
4067
4779
|
format(user, { format: outputFormat });
|
|
@@ -4071,7 +4783,7 @@ function registerAdminCommands(program) {
|
|
|
4071
4783
|
});
|
|
4072
4784
|
admin.command("subscription").description("Show current subscription").action(async (_options, cmd) => {
|
|
4073
4785
|
try {
|
|
4074
|
-
const outputFormat =
|
|
4786
|
+
const outputFormat = getOutputFormat14(cmd);
|
|
4075
4787
|
const api = createApiClient();
|
|
4076
4788
|
const sub = await api.admin.getCurrentSubscription();
|
|
4077
4789
|
format(sub, { format: outputFormat });
|
|
@@ -4082,7 +4794,7 @@ function registerAdminCommands(program) {
|
|
|
4082
4794
|
const settings = admin.command("settings").description("Manage settings");
|
|
4083
4795
|
settings.command("get").description("Get current settings").action(async (_options, cmd) => {
|
|
4084
4796
|
try {
|
|
4085
|
-
const outputFormat =
|
|
4797
|
+
const outputFormat = getOutputFormat14(cmd);
|
|
4086
4798
|
const api = createApiClient();
|
|
4087
4799
|
const s = await api.admin.getSettings();
|
|
4088
4800
|
format(s, { format: outputFormat });
|
|
@@ -4094,7 +4806,7 @@ function registerAdminCommands(program) {
|
|
|
4094
4806
|
try {
|
|
4095
4807
|
const api = createApiClient();
|
|
4096
4808
|
await api.admin.mergeSetting({ [key]: value });
|
|
4097
|
-
console.log(
|
|
4809
|
+
console.log(chalk21.green(`Setting "${key}" updated.`));
|
|
4098
4810
|
} catch (error) {
|
|
4099
4811
|
handleError(error);
|
|
4100
4812
|
}
|
|
@@ -4105,10 +4817,10 @@ function registerAdminCommands(program) {
|
|
|
4105
4817
|
const api = createApiClient();
|
|
4106
4818
|
if (options.longTerm) {
|
|
4107
4819
|
await api.storage.createLongTermFullBackup();
|
|
4108
|
-
console.log(
|
|
4820
|
+
console.log(chalk21.green("Full long-term backup initiated."));
|
|
4109
4821
|
} else {
|
|
4110
4822
|
await api.storage.createShortTermFullBackup();
|
|
4111
|
-
console.log(
|
|
4823
|
+
console.log(chalk21.green("Full short-term backup initiated."));
|
|
4112
4824
|
}
|
|
4113
4825
|
} catch (error) {
|
|
4114
4826
|
handleError(error);
|
|
@@ -4119,10 +4831,10 @@ function registerAdminCommands(program) {
|
|
|
4119
4831
|
const api = createApiClient();
|
|
4120
4832
|
if (options.longTerm) {
|
|
4121
4833
|
await api.storage.createLongTermProjectBackup();
|
|
4122
|
-
console.log(
|
|
4834
|
+
console.log(chalk21.green("Project long-term backup initiated."));
|
|
4123
4835
|
} else {
|
|
4124
4836
|
await api.storage.createShortTermProjectBackup();
|
|
4125
|
-
console.log(
|
|
4837
|
+
console.log(chalk21.green("Project short-term backup initiated."));
|
|
4126
4838
|
}
|
|
4127
4839
|
} catch (error) {
|
|
4128
4840
|
handleError(error);
|
|
@@ -4132,7 +4844,7 @@ function registerAdminCommands(program) {
|
|
|
4132
4844
|
try {
|
|
4133
4845
|
const api = createApiClient();
|
|
4134
4846
|
await api.storage.restoreProjectBackup({ projectId, projectBranch, bucketName, objectName });
|
|
4135
|
-
console.log(
|
|
4847
|
+
console.log(chalk21.green(`Restore initiated for ${projectId}/${projectBranch} from ${bucketName}/${objectName}.`));
|
|
4136
4848
|
} catch (error) {
|
|
4137
4849
|
handleError(error);
|
|
4138
4850
|
}
|
|
@@ -4141,7 +4853,7 @@ function registerAdminCommands(program) {
|
|
|
4141
4853
|
try {
|
|
4142
4854
|
const api = createApiClient();
|
|
4143
4855
|
await api.storage.restoreFullBackup({ bucketName, objectName });
|
|
4144
|
-
console.log(
|
|
4856
|
+
console.log(chalk21.green(`Full restore initiated from ${bucketName}/${objectName}.`));
|
|
4145
4857
|
} catch (error) {
|
|
4146
4858
|
handleError(error);
|
|
4147
4859
|
}
|
|
@@ -4151,10 +4863,10 @@ function registerAdminCommands(program) {
|
|
|
4151
4863
|
const api = createApiClient();
|
|
4152
4864
|
if (options.project) {
|
|
4153
4865
|
await api.index.rebuildProject(options.project);
|
|
4154
|
-
console.log(
|
|
4866
|
+
console.log(chalk21.green(`Index rebuild initiated for project "${options.project}".`));
|
|
4155
4867
|
} else {
|
|
4156
4868
|
await api.index.rebuildAll();
|
|
4157
|
-
console.log(
|
|
4869
|
+
console.log(chalk21.green("Index rebuild initiated for all projects."));
|
|
4158
4870
|
}
|
|
4159
4871
|
} catch (error) {
|
|
4160
4872
|
handleError(error);
|
|
@@ -4162,7 +4874,7 @@ function registerAdminCommands(program) {
|
|
|
4162
4874
|
});
|
|
4163
4875
|
admin.command("permissions").description("Show your permissions on a project").argument("<projectId>", "Project ID").action(async (projectId, _options, cmd) => {
|
|
4164
4876
|
try {
|
|
4165
|
-
const outputFormat =
|
|
4877
|
+
const outputFormat = getOutputFormat14(cmd);
|
|
4166
4878
|
const api = createApiClient();
|
|
4167
4879
|
const perm = await api.admin.getPermissions(projectId);
|
|
4168
4880
|
format(perm, { format: outputFormat });
|
|
@@ -4173,14 +4885,14 @@ function registerAdminCommands(program) {
|
|
|
4173
4885
|
}
|
|
4174
4886
|
|
|
4175
4887
|
// src/commands/status/summary.ts
|
|
4176
|
-
import
|
|
4888
|
+
import chalk22 from "chalk";
|
|
4177
4889
|
|
|
4178
4890
|
// src/client/services/status.ts
|
|
4179
4891
|
function createStatusService() {
|
|
4180
4892
|
const config = loadConfig();
|
|
4181
4893
|
const endpoint = resolveEndpoint(config);
|
|
4182
|
-
async function fetchJson(
|
|
4183
|
-
const url = `${endpoint}/status/v1${
|
|
4894
|
+
async function fetchJson(path11) {
|
|
4895
|
+
const url = `${endpoint}/status/v1${path11}`;
|
|
4184
4896
|
const response = await fetch(url, {
|
|
4185
4897
|
headers: { "Accept": "application/json" }
|
|
4186
4898
|
});
|
|
@@ -4199,24 +4911,24 @@ function createStatusService() {
|
|
|
4199
4911
|
|
|
4200
4912
|
// src/commands/status/summary.ts
|
|
4201
4913
|
var STATE_COLORS = {
|
|
4202
|
-
UP:
|
|
4203
|
-
DEGRADED:
|
|
4204
|
-
DOWN:
|
|
4205
|
-
UNKNOWN:
|
|
4914
|
+
UP: chalk22.green,
|
|
4915
|
+
DEGRADED: chalk22.yellow,
|
|
4916
|
+
DOWN: chalk22.red,
|
|
4917
|
+
UNKNOWN: chalk22.gray
|
|
4206
4918
|
};
|
|
4207
4919
|
function stateColor(state) {
|
|
4208
|
-
return STATE_COLORS[state] ??
|
|
4920
|
+
return STATE_COLORS[state] ?? chalk22.gray;
|
|
4209
4921
|
}
|
|
4210
4922
|
function stateSymbol(state) {
|
|
4211
4923
|
switch (state) {
|
|
4212
4924
|
case "UP":
|
|
4213
|
-
return
|
|
4925
|
+
return chalk22.green("\u25CF");
|
|
4214
4926
|
case "DEGRADED":
|
|
4215
|
-
return
|
|
4927
|
+
return chalk22.yellow("\u25CF");
|
|
4216
4928
|
case "DOWN":
|
|
4217
|
-
return
|
|
4929
|
+
return chalk22.red("\u25CF");
|
|
4218
4930
|
default:
|
|
4219
|
-
return
|
|
4931
|
+
return chalk22.gray("\u25CB");
|
|
4220
4932
|
}
|
|
4221
4933
|
}
|
|
4222
4934
|
function registerSummaryCommand(parent) {
|
|
@@ -4243,11 +4955,11 @@ function registerSummaryCommand(parent) {
|
|
|
4243
4955
|
}
|
|
4244
4956
|
console.log();
|
|
4245
4957
|
if (summary.openIncidents > 0) {
|
|
4246
|
-
console.log(
|
|
4958
|
+
console.log(chalk22.yellow(` ${summary.openIncidents} active incident(s)`));
|
|
4247
4959
|
} else {
|
|
4248
|
-
console.log(
|
|
4960
|
+
console.log(chalk22.dim(" No active incidents"));
|
|
4249
4961
|
}
|
|
4250
|
-
console.log(
|
|
4962
|
+
console.log(chalk22.dim(`
|
|
4251
4963
|
Platform v${version.platformVersion} \u2022 ${new Date(summary.timestamp).toLocaleString()}`));
|
|
4252
4964
|
console.log();
|
|
4253
4965
|
} catch (error) {
|
|
@@ -4257,17 +4969,17 @@ function registerSummaryCommand(parent) {
|
|
|
4257
4969
|
}
|
|
4258
4970
|
|
|
4259
4971
|
// src/commands/status/component.ts
|
|
4260
|
-
import
|
|
4972
|
+
import chalk23 from "chalk";
|
|
4261
4973
|
function stateSymbol2(state) {
|
|
4262
4974
|
switch (state) {
|
|
4263
4975
|
case "UP":
|
|
4264
|
-
return
|
|
4976
|
+
return chalk23.green("\u25CF");
|
|
4265
4977
|
case "DEGRADED":
|
|
4266
|
-
return
|
|
4978
|
+
return chalk23.yellow("\u25CF");
|
|
4267
4979
|
case "DOWN":
|
|
4268
|
-
return
|
|
4980
|
+
return chalk23.red("\u25CF");
|
|
4269
4981
|
default:
|
|
4270
|
-
return
|
|
4982
|
+
return chalk23.gray("\u25CB");
|
|
4271
4983
|
}
|
|
4272
4984
|
}
|
|
4273
4985
|
function registerComponentCommand(parent) {
|
|
@@ -4280,7 +4992,7 @@ function registerComponentCommand(parent) {
|
|
|
4280
4992
|
const match = components.find((c) => c.id === id || c.id === id + "-service");
|
|
4281
4993
|
if (!match) {
|
|
4282
4994
|
const available = components.map((c) => c.id).join(", ");
|
|
4283
|
-
console.error(
|
|
4995
|
+
console.error(chalk23.red(`Component "${id}" not found. Available: ${available}`));
|
|
4284
4996
|
process.exit(1);
|
|
4285
4997
|
}
|
|
4286
4998
|
if (outputFormat !== "human") {
|
|
@@ -4288,7 +5000,7 @@ function registerComponentCommand(parent) {
|
|
|
4288
5000
|
return;
|
|
4289
5001
|
}
|
|
4290
5002
|
console.log();
|
|
4291
|
-
console.log(` ${stateSymbol2(match.state)} ${
|
|
5003
|
+
console.log(` ${stateSymbol2(match.state)} ${chalk23.bold(match.id)} ${match.version ? chalk23.dim("v" + match.version) : ""}`);
|
|
4292
5004
|
console.log(` State: ${match.state}`);
|
|
4293
5005
|
if (match.lastCheckAt) {
|
|
4294
5006
|
console.log(` Last check: ${new Date(match.lastCheckAt).toLocaleString()}`);
|
|
@@ -4297,7 +5009,7 @@ function registerComponentCommand(parent) {
|
|
|
4297
5009
|
console.log();
|
|
4298
5010
|
console.log(" Checks:");
|
|
4299
5011
|
for (const check of match.checks) {
|
|
4300
|
-
const cat = check.category ?
|
|
5012
|
+
const cat = check.category ? chalk23.dim(` (${check.category})`) : "";
|
|
4301
5013
|
console.log(` ${stateSymbol2(check.state)} ${check.name}${cat}`);
|
|
4302
5014
|
}
|
|
4303
5015
|
}
|
|
@@ -4309,12 +5021,12 @@ function registerComponentCommand(parent) {
|
|
|
4309
5021
|
}
|
|
4310
5022
|
|
|
4311
5023
|
// src/commands/status/incidents.ts
|
|
4312
|
-
import
|
|
5024
|
+
import chalk24 from "chalk";
|
|
4313
5025
|
var SEVERITY_COLORS = {
|
|
4314
|
-
ERROR:
|
|
4315
|
-
WARNING:
|
|
4316
|
-
INFO:
|
|
4317
|
-
MAINTENANCE:
|
|
5026
|
+
ERROR: chalk24.red,
|
|
5027
|
+
WARNING: chalk24.yellow,
|
|
5028
|
+
INFO: chalk24.blue,
|
|
5029
|
+
MAINTENANCE: chalk24.cyan
|
|
4318
5030
|
};
|
|
4319
5031
|
function registerIncidentsCommand(parent) {
|
|
4320
5032
|
parent.command("incidents").description("List recent incidents").option("-w, --window <window>", "Time window (e.g. 24h, 48h)", "24h").action(async (options, cmd) => {
|
|
@@ -4328,22 +5040,22 @@ function registerIncidentsCommand(parent) {
|
|
|
4328
5040
|
return;
|
|
4329
5041
|
}
|
|
4330
5042
|
if (incidents.length === 0) {
|
|
4331
|
-
console.log(
|
|
5043
|
+
console.log(chalk24.dim(`
|
|
4332
5044
|
No incidents in the last ${options.window}.
|
|
4333
5045
|
`));
|
|
4334
5046
|
return;
|
|
4335
5047
|
}
|
|
4336
5048
|
console.log();
|
|
4337
5049
|
for (const incident of incidents) {
|
|
4338
|
-
const color = SEVERITY_COLORS[incident.severity] ??
|
|
5050
|
+
const color = SEVERITY_COLORS[incident.severity] ?? chalk24.gray;
|
|
4339
5051
|
const severity = color(incident.severity.padEnd(8));
|
|
4340
5052
|
const time = incident.startedAt ? new Date(incident.startedAt).toLocaleString() : "";
|
|
4341
|
-
const resolved = incident.resolvedAt ?
|
|
5053
|
+
const resolved = incident.resolvedAt ? chalk24.green(" [resolved]") : chalk24.yellow(" [open]");
|
|
4342
5054
|
console.log(` ${severity} ${incident.summary}${resolved}`);
|
|
4343
|
-
console.log(
|
|
5055
|
+
console.log(chalk24.dim(` ${time}`));
|
|
4344
5056
|
for (const update of incident.updates) {
|
|
4345
5057
|
const updateTime = new Date(update.at).toLocaleTimeString();
|
|
4346
|
-
console.log(
|
|
5058
|
+
console.log(chalk24.dim(` ${updateTime} ${update.status} ${update.message}`));
|
|
4347
5059
|
}
|
|
4348
5060
|
console.log();
|
|
4349
5061
|
}
|
|
@@ -4362,9 +5074,9 @@ function registerStatusCommands(program) {
|
|
|
4362
5074
|
}
|
|
4363
5075
|
|
|
4364
5076
|
// src/commands/analyze/index.ts
|
|
4365
|
-
import
|
|
4366
|
-
import * as
|
|
4367
|
-
import * as
|
|
5077
|
+
import chalk25 from "chalk";
|
|
5078
|
+
import * as fs8 from "fs";
|
|
5079
|
+
import * as path7 from "path";
|
|
4368
5080
|
import { spawn as spawn2 } from "child_process";
|
|
4369
5081
|
function formatDuration(ms) {
|
|
4370
5082
|
const seconds = Math.floor(ms / 1e3);
|
|
@@ -4379,7 +5091,7 @@ function openUrl(url) {
|
|
|
4379
5091
|
const args = process.platform === "win32" ? ["/c", "start", '""', url] : [url];
|
|
4380
5092
|
spawn2(cmd, args, { detached: true, stdio: "ignore" }).unref();
|
|
4381
5093
|
}
|
|
4382
|
-
function
|
|
5094
|
+
function getOutputFormat15(cmd) {
|
|
4383
5095
|
const config = loadConfig();
|
|
4384
5096
|
const globalOpts = cmd.optsWithGlobals();
|
|
4385
5097
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -4399,20 +5111,20 @@ function isTerminalState(state) {
|
|
|
4399
5111
|
return state === "COMPLETED" || state === "FAILED" || state === "CANCELLED";
|
|
4400
5112
|
}
|
|
4401
5113
|
function multipartFromFile(file) {
|
|
4402
|
-
const buffer =
|
|
5114
|
+
const buffer = fs8.readFileSync(file);
|
|
4403
5115
|
const blob = new Blob([buffer]);
|
|
4404
5116
|
const formData = new FormData();
|
|
4405
|
-
formData.append("content", blob,
|
|
5117
|
+
formData.append("content", blob, path7.basename(file));
|
|
4406
5118
|
return formData;
|
|
4407
5119
|
}
|
|
4408
5120
|
async function runAnalysis(file, options, cmd) {
|
|
4409
|
-
if (!
|
|
4410
|
-
console.error(
|
|
5121
|
+
if (!fs8.existsSync(file)) {
|
|
5122
|
+
console.error(chalk25.red(`File not found: ${file}`));
|
|
4411
5123
|
process.exit(1);
|
|
4412
5124
|
}
|
|
4413
5125
|
const api = createApiClient();
|
|
4414
5126
|
const visibility = parseVisibility(options.visibility);
|
|
4415
|
-
const name = options.name ??
|
|
5127
|
+
const name = options.name ?? path7.basename(file, path7.extname(file));
|
|
4416
5128
|
const request = {
|
|
4417
5129
|
name,
|
|
4418
5130
|
description: options.description || null,
|
|
@@ -4426,21 +5138,21 @@ async function runAnalysis(file, options, cmd) {
|
|
|
4426
5138
|
};
|
|
4427
5139
|
process.stdout.write(`Creating analysis "${name}" ...`);
|
|
4428
5140
|
const created = await api.analysis.create(request);
|
|
4429
|
-
console.log(
|
|
4430
|
-
console.log(
|
|
4431
|
-
process.stdout.write(`Uploading ${
|
|
5141
|
+
console.log(chalk25.green(" done"));
|
|
5142
|
+
console.log(chalk25.dim(` analysisId: ${created.analysisId}`));
|
|
5143
|
+
process.stdout.write(`Uploading ${path7.basename(file)} ...`);
|
|
4432
5144
|
await api.analysis.uploadDataMultipart(created.analysisId, multipartFromFile(file));
|
|
4433
|
-
console.log(
|
|
5145
|
+
console.log(chalk25.green(" done"));
|
|
4434
5146
|
process.stdout.write("Queuing analysis run ...");
|
|
4435
5147
|
const run = await api.analysis.runAnalysis(created.analysisId);
|
|
4436
|
-
console.log(
|
|
4437
|
-
console.log(
|
|
5148
|
+
console.log(chalk25.green(" done"));
|
|
5149
|
+
console.log(chalk25.dim(` runId: ${run.runId}`));
|
|
4438
5150
|
console.log();
|
|
4439
5151
|
await monitorRun(api, created.analysisId, run.runId, parseFloat(options.hours), cmd);
|
|
4440
5152
|
}
|
|
4441
5153
|
async function monitorRun(api, analysisId, runId, hoursForProgress, cmd) {
|
|
4442
5154
|
const config = loadConfig();
|
|
4443
|
-
const outputFormat =
|
|
5155
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
4444
5156
|
const computationMs = hoursForProgress * 60 * 60 * 1e3;
|
|
4445
5157
|
const startMs = Date.now();
|
|
4446
5158
|
const seenOutputIds = /* @__PURE__ */ new Set();
|
|
@@ -4459,7 +5171,7 @@ async function monitorRun(api, analysisId, runId, hoursForProgress, cmd) {
|
|
|
4459
5171
|
if (!seenOutputIds.has(out.outputId)) {
|
|
4460
5172
|
seenOutputIds.add(out.outputId);
|
|
4461
5173
|
if (outputFormat === "human") {
|
|
4462
|
-
console.log(` ${
|
|
5174
|
+
console.log(` ${chalk25.dim("Output:")} ${out.output}`);
|
|
4463
5175
|
}
|
|
4464
5176
|
}
|
|
4465
5177
|
}
|
|
@@ -4472,7 +5184,7 @@ async function monitorRun(api, analysisId, runId, hoursForProgress, cmd) {
|
|
|
4472
5184
|
const durationStr = formatDuration(duration);
|
|
4473
5185
|
if (run.state === "COMPLETED") {
|
|
4474
5186
|
if (outputFormat === "human") {
|
|
4475
|
-
console.log(
|
|
5187
|
+
console.log(chalk25.green(`Analysis complete! (${durationStr})`));
|
|
4476
5188
|
try {
|
|
4477
5189
|
const nav = await api.analysis.getNavigation(analysisId);
|
|
4478
5190
|
const endpoint = config.profiles[config.currentProfile]?.endpoint ?? "https://diafunc.com";
|
|
@@ -4484,13 +5196,13 @@ async function monitorRun(api, analysisId, runId, hoursForProgress, cmd) {
|
|
|
4484
5196
|
}
|
|
4485
5197
|
} else if (run.state === "CANCELLED") {
|
|
4486
5198
|
if (outputFormat === "human") {
|
|
4487
|
-
console.log(
|
|
5199
|
+
console.log(chalk25.yellow("Analysis cancelled."));
|
|
4488
5200
|
} else {
|
|
4489
5201
|
format({ status: "cancelled", runId, analysisId }, { format: outputFormat });
|
|
4490
5202
|
}
|
|
4491
5203
|
} else {
|
|
4492
5204
|
if (outputFormat === "human") {
|
|
4493
|
-
console.log(
|
|
5205
|
+
console.log(chalk25.red("Analysis failed."));
|
|
4494
5206
|
if (run.errorMessage) console.log(` Error: ${run.errorMessage}`);
|
|
4495
5207
|
} else {
|
|
4496
5208
|
format({ status: "failed", runId, analysisId, error: run.errorMessage }, { format: outputFormat });
|
|
@@ -4510,7 +5222,7 @@ async function monitorRun(api, analysisId, runId, hoursForProgress, cmd) {
|
|
|
4510
5222
|
}
|
|
4511
5223
|
}
|
|
4512
5224
|
async function listAnalyses(limit, cmd) {
|
|
4513
|
-
const outputFormat =
|
|
5225
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
4514
5226
|
const api = createApiClient();
|
|
4515
5227
|
const analyses = await api.analysis.getRecent(limit);
|
|
4516
5228
|
format(analyses.map((a) => ({
|
|
@@ -4528,11 +5240,11 @@ async function listAnalyses(limit, cmd) {
|
|
|
4528
5240
|
});
|
|
4529
5241
|
}
|
|
4530
5242
|
async function getAnalysisDetails(analysisId, cmd) {
|
|
4531
|
-
const outputFormat =
|
|
5243
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
4532
5244
|
const api = createApiClient();
|
|
4533
5245
|
const result = analysisId ? await api.analysis.get(analysisId) : await api.analysis.getLast();
|
|
4534
5246
|
if (!result.analysis) {
|
|
4535
|
-
console.log(
|
|
5247
|
+
console.log(chalk25.dim("No analysis found."));
|
|
4536
5248
|
return;
|
|
4537
5249
|
}
|
|
4538
5250
|
format(result.analysis, { format: outputFormat });
|
|
@@ -4541,18 +5253,18 @@ async function watchAnalysis(analysisId, cmd) {
|
|
|
4541
5253
|
const api = createApiClient();
|
|
4542
5254
|
const result = analysisId ? await api.analysis.get(analysisId) : await api.analysis.getLast();
|
|
4543
5255
|
if (!result.analysis) {
|
|
4544
|
-
console.log(
|
|
5256
|
+
console.log(chalk25.dim("No analysis found."));
|
|
4545
5257
|
return;
|
|
4546
5258
|
}
|
|
4547
5259
|
const recipe = result.analysis;
|
|
4548
5260
|
const runs = await api.analysis.getRunsForAnalysis(recipe.analysisId, 1);
|
|
4549
5261
|
if (runs.length === 0) {
|
|
4550
|
-
console.log(
|
|
5262
|
+
console.log(chalk25.dim("No runs for this analysis."));
|
|
4551
5263
|
return;
|
|
4552
5264
|
}
|
|
4553
5265
|
const latest = runs[0];
|
|
4554
5266
|
if (isTerminalState(latest.state)) {
|
|
4555
|
-
console.log(
|
|
5267
|
+
console.log(chalk25.green(`Latest run already in terminal state: ${latest.state}`));
|
|
4556
5268
|
try {
|
|
4557
5269
|
const nav = await api.analysis.getNavigation(recipe.analysisId);
|
|
4558
5270
|
const config = loadConfig();
|
|
@@ -4568,16 +5280,16 @@ async function watchAnalysis(analysisId, cmd) {
|
|
|
4568
5280
|
async function rerunAnalysis(analysisId) {
|
|
4569
5281
|
const api = createApiClient();
|
|
4570
5282
|
const run = await api.analysis.runAnalysis(analysisId);
|
|
4571
|
-
console.log(
|
|
4572
|
-
console.log(
|
|
5283
|
+
console.log(chalk25.green(`\u2713 Queued new run ${run.runId} for analysis ${analysisId}`));
|
|
5284
|
+
console.log(chalk25.dim(` State: ${run.state}`));
|
|
4573
5285
|
console.log();
|
|
4574
|
-
console.log(
|
|
5286
|
+
console.log(chalk25.dim("Track progress: diafunc analyze watch " + analysisId));
|
|
4575
5287
|
}
|
|
4576
5288
|
async function openAnalysis(analysisId) {
|
|
4577
5289
|
const api = createApiClient();
|
|
4578
5290
|
const result = analysisId ? await api.analysis.get(analysisId) : await api.analysis.getLast();
|
|
4579
5291
|
if (!result.analysis) {
|
|
4580
|
-
console.log(
|
|
5292
|
+
console.log(chalk25.dim("No analysis found."));
|
|
4581
5293
|
return;
|
|
4582
5294
|
}
|
|
4583
5295
|
const config = loadConfig();
|
|
@@ -4588,11 +5300,11 @@ async function openAnalysis(analysisId) {
|
|
|
4588
5300
|
console.log(`Opening ${url} ...`);
|
|
4589
5301
|
openUrl(url);
|
|
4590
5302
|
} catch {
|
|
4591
|
-
console.log(
|
|
5303
|
+
console.log(chalk25.dim("Notebook not yet provisioned \u2014 run the analysis first."));
|
|
4592
5304
|
}
|
|
4593
5305
|
}
|
|
4594
5306
|
async function createRecipe(options, cmd) {
|
|
4595
|
-
const outputFormat =
|
|
5307
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
4596
5308
|
const api = createApiClient();
|
|
4597
5309
|
const visibility = parseVisibility(options.visibility);
|
|
4598
5310
|
const request = {
|
|
@@ -4612,14 +5324,14 @@ async function createRecipe(options, cmd) {
|
|
|
4612
5324
|
async function deleteAnalysis(analysisId) {
|
|
4613
5325
|
const api = createApiClient();
|
|
4614
5326
|
await api.analysis.delete(analysisId);
|
|
4615
|
-
console.log(
|
|
5327
|
+
console.log(chalk25.green(`\u2713 Deleted analysis ${analysisId}`));
|
|
4616
5328
|
}
|
|
4617
5329
|
async function patchAndPrint(analysisId, value, handler, successLabel, cmd) {
|
|
4618
|
-
const outputFormat =
|
|
5330
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
4619
5331
|
const api = createApiClient();
|
|
4620
5332
|
const updated = await handler(api, analysisId, value);
|
|
4621
5333
|
if (outputFormat === "human") {
|
|
4622
|
-
console.log(
|
|
5334
|
+
console.log(chalk25.green(`\u2713 ${successLabel} updated for analysis ${analysisId}`));
|
|
4623
5335
|
} else {
|
|
4624
5336
|
format(updated, { format: outputFormat });
|
|
4625
5337
|
}
|
|
@@ -4628,38 +5340,38 @@ async function uploadData(analysisId, file, options) {
|
|
|
4628
5340
|
const api = createApiClient();
|
|
4629
5341
|
if (options.url) {
|
|
4630
5342
|
if (file) {
|
|
4631
|
-
console.error(
|
|
5343
|
+
console.error(chalk25.red("Provide either a file or --url, not both."));
|
|
4632
5344
|
process.exit(1);
|
|
4633
5345
|
}
|
|
4634
5346
|
process.stdout.write(`Uploading from ${options.url} ...`);
|
|
4635
5347
|
await api.analysis.uploadDataUrl(analysisId, { dataUrl: options.url });
|
|
4636
|
-
console.log(
|
|
5348
|
+
console.log(chalk25.green(" done"));
|
|
4637
5349
|
return;
|
|
4638
5350
|
}
|
|
4639
5351
|
if (!file) {
|
|
4640
|
-
console.error(
|
|
5352
|
+
console.error(chalk25.red("Provide a file path or --url <URL>."));
|
|
4641
5353
|
process.exit(1);
|
|
4642
5354
|
}
|
|
4643
|
-
if (!
|
|
4644
|
-
console.error(
|
|
5355
|
+
if (!fs8.existsSync(file)) {
|
|
5356
|
+
console.error(chalk25.red(`File not found: ${file}`));
|
|
4645
5357
|
process.exit(1);
|
|
4646
5358
|
}
|
|
4647
|
-
process.stdout.write(`Uploading ${
|
|
5359
|
+
process.stdout.write(`Uploading ${path7.basename(file)} ...`);
|
|
4648
5360
|
await api.analysis.uploadDataMultipart(analysisId, multipartFromFile(file));
|
|
4649
|
-
console.log(
|
|
5361
|
+
console.log(chalk25.green(" done"));
|
|
4650
5362
|
}
|
|
4651
5363
|
async function listColumns(analysisId, cmd) {
|
|
4652
|
-
const outputFormat =
|
|
5364
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
4653
5365
|
const api = createApiClient();
|
|
4654
5366
|
const columns = await api.analysis.getColumns(analysisId);
|
|
4655
5367
|
if (columns.length === 0) {
|
|
4656
|
-
console.log(
|
|
5368
|
+
console.log(chalk25.dim("No columns yet \u2014 upload data first."));
|
|
4657
5369
|
return;
|
|
4658
5370
|
}
|
|
4659
5371
|
format(columns, { format: outputFormat, columns: ["name", "valueType"] });
|
|
4660
5372
|
}
|
|
4661
5373
|
async function listRuns(analysisId, count, cmd) {
|
|
4662
|
-
const outputFormat =
|
|
5374
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
4663
5375
|
const api = createApiClient();
|
|
4664
5376
|
const runs = await api.analysis.getRunsForAnalysis(analysisId, count);
|
|
4665
5377
|
format(runs.map((r) => ({
|
|
@@ -4675,17 +5387,17 @@ async function listRuns(analysisId, count, cmd) {
|
|
|
4675
5387
|
});
|
|
4676
5388
|
}
|
|
4677
5389
|
async function cancelRun(runId, cmd) {
|
|
4678
|
-
const outputFormat =
|
|
5390
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
4679
5391
|
const api = createApiClient();
|
|
4680
5392
|
const run = await api.analysis.cancelRun(runId);
|
|
4681
5393
|
if (outputFormat === "human") {
|
|
4682
|
-
console.log(
|
|
5394
|
+
console.log(chalk25.green(`\u2713 Run ${run.runId} state: ${run.state}`));
|
|
4683
5395
|
} else {
|
|
4684
5396
|
format(run, { format: outputFormat });
|
|
4685
5397
|
}
|
|
4686
5398
|
}
|
|
4687
5399
|
async function listPresets(cmd) {
|
|
4688
|
-
const outputFormat =
|
|
5400
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
4689
5401
|
const api = createApiClient();
|
|
4690
5402
|
const presets = await api.analysis.getPresets();
|
|
4691
5403
|
format(presets.map((p) => ({
|
|
@@ -4702,17 +5414,17 @@ async function listPresets(cmd) {
|
|
|
4702
5414
|
});
|
|
4703
5415
|
}
|
|
4704
5416
|
async function getPreset(presetId, cmd) {
|
|
4705
|
-
const outputFormat =
|
|
5417
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
4706
5418
|
const api = createApiClient();
|
|
4707
5419
|
const opt = await api.analysis.getPreset(presetId);
|
|
4708
5420
|
if (!opt.preset) {
|
|
4709
|
-
console.log(
|
|
5421
|
+
console.log(chalk25.dim("Preset not found."));
|
|
4710
5422
|
return;
|
|
4711
5423
|
}
|
|
4712
5424
|
format(opt.preset, { format: outputFormat });
|
|
4713
5425
|
}
|
|
4714
5426
|
async function savePreset(options, cmd) {
|
|
4715
|
-
const outputFormat =
|
|
5427
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
4716
5428
|
const api = createApiClient();
|
|
4717
5429
|
const preset = {
|
|
4718
5430
|
presetId: options.id ?? null,
|
|
@@ -4729,10 +5441,10 @@ async function savePreset(options, cmd) {
|
|
|
4729
5441
|
async function deletePreset(presetId) {
|
|
4730
5442
|
const api = createApiClient();
|
|
4731
5443
|
await api.analysis.deletePreset(presetId);
|
|
4732
|
-
console.log(
|
|
5444
|
+
console.log(chalk25.green(`\u2713 Deleted preset ${presetId}`));
|
|
4733
5445
|
}
|
|
4734
5446
|
async function listTriggers(analysisId, cmd) {
|
|
4735
|
-
const outputFormat =
|
|
5447
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
4736
5448
|
const api = createApiClient();
|
|
4737
5449
|
const triggers = await api.analysis.listTriggers(analysisId);
|
|
4738
5450
|
format(triggers.map((t) => ({
|
|
@@ -4747,10 +5459,10 @@ async function listTriggers(analysisId, cmd) {
|
|
|
4747
5459
|
});
|
|
4748
5460
|
}
|
|
4749
5461
|
async function createTrigger(analysisId, kind, schedule, cmd) {
|
|
4750
|
-
const outputFormat =
|
|
5462
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
4751
5463
|
const upper = kind.toUpperCase();
|
|
4752
5464
|
if (upper !== "ONCE" && upper !== "CRON") {
|
|
4753
|
-
console.error(
|
|
5465
|
+
console.error(chalk25.red(`Invalid kind "${kind}" \u2014 must be ONCE or CRON.`));
|
|
4754
5466
|
process.exit(1);
|
|
4755
5467
|
}
|
|
4756
5468
|
const api = createApiClient();
|
|
@@ -4763,17 +5475,28 @@ async function createTrigger(analysisId, kind, schedule, cmd) {
|
|
|
4763
5475
|
async function deleteTrigger(triggerId) {
|
|
4764
5476
|
const api = createApiClient();
|
|
4765
5477
|
await api.analysis.deleteTrigger(triggerId);
|
|
4766
|
-
console.log(
|
|
4767
|
-
}
|
|
4768
|
-
async function
|
|
4769
|
-
const outputFormat =
|
|
4770
|
-
|
|
4771
|
-
if (
|
|
4772
|
-
|
|
5478
|
+
console.log(chalk25.green(`\u2713 Deleted trigger ${triggerId}`));
|
|
5479
|
+
}
|
|
5480
|
+
async function updateTriggerCmd(triggerId, options, cmd) {
|
|
5481
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
5482
|
+
let activeFlag;
|
|
5483
|
+
if (options.active !== void 0) {
|
|
5484
|
+
const lc = options.active.toLowerCase();
|
|
5485
|
+
if (lc !== "true" && lc !== "false") {
|
|
5486
|
+
console.error(chalk25.red(`Invalid --active value "${options.active}" \u2014 must be true or false.`));
|
|
5487
|
+
process.exit(1);
|
|
5488
|
+
}
|
|
5489
|
+
activeFlag = lc === "true";
|
|
5490
|
+
}
|
|
5491
|
+
if (activeFlag === void 0 && !options.schedule) {
|
|
5492
|
+
console.error(chalk25.red("Pass at least one of --active or --schedule."));
|
|
4773
5493
|
process.exit(1);
|
|
4774
5494
|
}
|
|
4775
5495
|
const api = createApiClient();
|
|
4776
|
-
const trigger = await api.analysis.updateTrigger(triggerId, {
|
|
5496
|
+
const trigger = await api.analysis.updateTrigger(triggerId, {
|
|
5497
|
+
active: activeFlag ?? null,
|
|
5498
|
+
scheduleSpec: options.schedule ?? null
|
|
5499
|
+
});
|
|
4777
5500
|
format(trigger, { format: outputFormat });
|
|
4778
5501
|
}
|
|
4779
5502
|
function registerAnalyzeCommand(program) {
|
|
@@ -4831,215 +5554,774 @@ function registerAnalyzeCommand(program) {
|
|
|
4831
5554
|
handleError(error);
|
|
4832
5555
|
}
|
|
4833
5556
|
});
|
|
4834
|
-
analyze.command("delete").description("Delete an analysis (cancels in-flight run; removes underlying project)").argument("<id>", "Analysis ID").action(async (id) => {
|
|
4835
|
-
try {
|
|
4836
|
-
await deleteAnalysis(id);
|
|
4837
|
-
} catch (error) {
|
|
4838
|
-
handleError(error);
|
|
4839
|
-
}
|
|
5557
|
+
analyze.command("delete").description("Delete an analysis (cancels in-flight run; removes underlying project)").argument("<id>", "Analysis ID").action(async (id) => {
|
|
5558
|
+
try {
|
|
5559
|
+
await deleteAnalysis(id);
|
|
5560
|
+
} catch (error) {
|
|
5561
|
+
handleError(error);
|
|
5562
|
+
}
|
|
5563
|
+
});
|
|
5564
|
+
analyze.command("rename").description("Set the analysis name").argument("<id>", "Analysis ID").argument("<name>", "New name").action(async (id, name, _options, cmd) => {
|
|
5565
|
+
try {
|
|
5566
|
+
await patchAndPrint(
|
|
5567
|
+
id,
|
|
5568
|
+
name,
|
|
5569
|
+
(api, aid, v) => api.analysis.patchName(aid, { name: v }),
|
|
5570
|
+
"Name",
|
|
5571
|
+
cmd
|
|
5572
|
+
);
|
|
5573
|
+
} catch (error) {
|
|
5574
|
+
handleError(error);
|
|
5575
|
+
}
|
|
5576
|
+
});
|
|
5577
|
+
analyze.command("description").description("Set or clear the analysis description (empty string clears)").argument("<id>", "Analysis ID").argument("<text>", "New description (empty string to clear)").action(async (id, text, _options, cmd) => {
|
|
5578
|
+
try {
|
|
5579
|
+
await patchAndPrint(
|
|
5580
|
+
id,
|
|
5581
|
+
text,
|
|
5582
|
+
(api, aid, v) => api.analysis.patchDescription(aid, { description: v === "" ? null : v }),
|
|
5583
|
+
"Description",
|
|
5584
|
+
cmd
|
|
5585
|
+
);
|
|
5586
|
+
} catch (error) {
|
|
5587
|
+
handleError(error);
|
|
5588
|
+
}
|
|
5589
|
+
});
|
|
5590
|
+
analyze.command("visibility").description("Set analysis visibility (PRIVATE or PUBLIC)").argument("<id>", "Analysis ID").argument("<vis>", "PRIVATE or PUBLIC").action(async (id, vis, _options, cmd) => {
|
|
5591
|
+
try {
|
|
5592
|
+
const visibility = parseVisibility(vis);
|
|
5593
|
+
await patchAndPrint(
|
|
5594
|
+
id,
|
|
5595
|
+
visibility,
|
|
5596
|
+
(api, aid, v) => api.analysis.patchVisibility(aid, { visibility: v }),
|
|
5597
|
+
"Visibility",
|
|
5598
|
+
cmd
|
|
5599
|
+
);
|
|
5600
|
+
} catch (error) {
|
|
5601
|
+
handleError(error);
|
|
5602
|
+
}
|
|
5603
|
+
});
|
|
5604
|
+
analyze.command("introduction").description("Set or clear the markdown introduction").argument("<id>", "Analysis ID").argument("<markdown>", "New introduction (empty string to clear)").action(async (id, markdown, _options, cmd) => {
|
|
5605
|
+
try {
|
|
5606
|
+
await patchAndPrint(
|
|
5607
|
+
id,
|
|
5608
|
+
markdown,
|
|
5609
|
+
(api, aid, v) => api.analysis.patchIntroduction(aid, { introduction: v === "" ? null : v }),
|
|
5610
|
+
"Introduction",
|
|
5611
|
+
cmd
|
|
5612
|
+
);
|
|
5613
|
+
} catch (error) {
|
|
5614
|
+
handleError(error);
|
|
5615
|
+
}
|
|
5616
|
+
});
|
|
5617
|
+
analyze.command("hours").description("Set the compute-hours budget for the next run").argument("<id>", "Analysis ID").argument("<hours>", "Compute hours (e.g. 4)").action(async (id, hours, _options, cmd) => {
|
|
5618
|
+
try {
|
|
5619
|
+
await patchAndPrint(
|
|
5620
|
+
id,
|
|
5621
|
+
hours,
|
|
5622
|
+
(api, aid, v) => api.analysis.patchHours(aid, { hours: v }),
|
|
5623
|
+
"Hours",
|
|
5624
|
+
cmd
|
|
5625
|
+
);
|
|
5626
|
+
} catch (error) {
|
|
5627
|
+
handleError(error);
|
|
5628
|
+
}
|
|
5629
|
+
});
|
|
5630
|
+
analyze.command("budget").description("Set the token-credit budget for the next run").argument("<id>", "Analysis ID").argument("<credits>", "Credit budget (e.g. 10000)").action(async (id, credits, _options, cmd) => {
|
|
5631
|
+
try {
|
|
5632
|
+
await patchAndPrint(
|
|
5633
|
+
id,
|
|
5634
|
+
credits,
|
|
5635
|
+
(api, aid, v) => api.analysis.patchBudget(aid, { budget: v }),
|
|
5636
|
+
"Budget",
|
|
5637
|
+
cmd
|
|
5638
|
+
);
|
|
5639
|
+
} catch (error) {
|
|
5640
|
+
handleError(error);
|
|
5641
|
+
}
|
|
5642
|
+
});
|
|
5643
|
+
analyze.command("targets").description("Set the target column names (comma-separated)").argument("<id>", "Analysis ID").argument("<csv>", "Comma-separated target column names").action(async (id, csv, _options, cmd) => {
|
|
5644
|
+
try {
|
|
5645
|
+
const targets = parseCsv(csv) ?? [];
|
|
5646
|
+
await patchAndPrint(
|
|
5647
|
+
id,
|
|
5648
|
+
csv,
|
|
5649
|
+
(api, aid) => api.analysis.patchTargets(aid, { targets }),
|
|
5650
|
+
"Targets",
|
|
5651
|
+
cmd
|
|
5652
|
+
);
|
|
5653
|
+
} catch (error) {
|
|
5654
|
+
handleError(error);
|
|
5655
|
+
}
|
|
5656
|
+
});
|
|
5657
|
+
analyze.command("questions").description("Set the questions list (comma-separated)").argument("<id>", "Analysis ID").argument("<csv>", "Comma-separated questions (empty string to clear)").action(async (id, csv, _options, cmd) => {
|
|
5658
|
+
try {
|
|
5659
|
+
const questions = parseCsv(csv) ?? [];
|
|
5660
|
+
await patchAndPrint(
|
|
5661
|
+
id,
|
|
5662
|
+
csv,
|
|
5663
|
+
(api, aid) => api.analysis.patchQuestions(aid, { questions }),
|
|
5664
|
+
"Questions",
|
|
5665
|
+
cmd
|
|
5666
|
+
);
|
|
5667
|
+
} catch (error) {
|
|
5668
|
+
handleError(error);
|
|
5669
|
+
}
|
|
5670
|
+
});
|
|
5671
|
+
analyze.command("segment").description("Set or clear the segmentation column (empty string clears)").argument("<id>", "Analysis ID").argument("<name>", "Column name (empty string to clear)").action(async (id, name, _options, cmd) => {
|
|
5672
|
+
try {
|
|
5673
|
+
await patchAndPrint(
|
|
5674
|
+
id,
|
|
5675
|
+
name,
|
|
5676
|
+
(api, aid, v) => api.analysis.patchSegment(aid, { segment: v === "" ? null : v }),
|
|
5677
|
+
"Segment",
|
|
5678
|
+
cmd
|
|
5679
|
+
);
|
|
5680
|
+
} catch (error) {
|
|
5681
|
+
handleError(error);
|
|
5682
|
+
}
|
|
5683
|
+
});
|
|
5684
|
+
analyze.command("upload").description("Replace the analysis raw-data table with a new CSV (file path or --url)").argument("<id>", "Analysis ID").argument("[file]", "CSV file to upload").option("--url <url>", "HTTPS URL to fetch the CSV from (mutually exclusive with file)").action(async (id, file, options) => {
|
|
5685
|
+
try {
|
|
5686
|
+
await uploadData(id, file, options);
|
|
5687
|
+
} catch (error) {
|
|
5688
|
+
handleError(error);
|
|
5689
|
+
}
|
|
5690
|
+
});
|
|
5691
|
+
analyze.command("columns").description("List columns of the analysis raw-data table").argument("<id>", "Analysis ID").action(async (id, _options, cmd) => {
|
|
5692
|
+
try {
|
|
5693
|
+
await listColumns(id, cmd);
|
|
5694
|
+
} catch (error) {
|
|
5695
|
+
handleError(error);
|
|
5696
|
+
}
|
|
5697
|
+
});
|
|
5698
|
+
analyze.command("runs").description("List recent runs for an analysis (newest first)").argument("<id>", "Analysis ID").option("--count <n>", "Max number of runs to show", "20").action(async (id, options, cmd) => {
|
|
5699
|
+
try {
|
|
5700
|
+
await listRuns(id, parseInt(options.count, 10), cmd);
|
|
5701
|
+
} catch (error) {
|
|
5702
|
+
handleError(error);
|
|
5703
|
+
}
|
|
5704
|
+
});
|
|
5705
|
+
analyze.command("cancel").description("Cancel a non-terminal run (idempotent on terminal runs)").argument("<runId>", "Run ID to cancel").action(async (runId, _options, cmd) => {
|
|
5706
|
+
try {
|
|
5707
|
+
await cancelRun(runId, cmd);
|
|
5708
|
+
} catch (error) {
|
|
5709
|
+
handleError(error);
|
|
5710
|
+
}
|
|
5711
|
+
});
|
|
5712
|
+
const presets = analyze.command("presets").description("Manage saved analysis presets");
|
|
5713
|
+
presets.command("list").description("List your analysis presets").action(async (_options, cmd) => {
|
|
5714
|
+
try {
|
|
5715
|
+
await listPresets(cmd);
|
|
5716
|
+
} catch (error) {
|
|
5717
|
+
handleError(error);
|
|
5718
|
+
}
|
|
5719
|
+
});
|
|
5720
|
+
presets.command("get").description("Show details of a preset").argument("<id>", "Preset ID").action(async (id, _options, cmd) => {
|
|
5721
|
+
try {
|
|
5722
|
+
await getPreset(id, cmd);
|
|
5723
|
+
} catch (error) {
|
|
5724
|
+
handleError(error);
|
|
5725
|
+
}
|
|
5726
|
+
});
|
|
5727
|
+
presets.command("save").description("Create a new preset (omit --id) or update an existing one (with --id)").requiredOption("--name <name>", "Preset name").requiredOption("--targets <csv>", "Comma-separated target column names").requiredOption("--hours <h>", "Compute hours").requiredOption("--budget <credits>", "Credit budget").option("--questions <csv>", "Comma-separated questions").option("--segment <name>", "Segmentation column").option("--id <id>", "Existing preset ID (update mode)").action(async (options, cmd) => {
|
|
5728
|
+
try {
|
|
5729
|
+
await savePreset(options, cmd);
|
|
5730
|
+
} catch (error) {
|
|
5731
|
+
handleError(error);
|
|
5732
|
+
}
|
|
5733
|
+
});
|
|
5734
|
+
presets.command("delete").description("Delete a preset").argument("<id>", "Preset ID").action(async (id) => {
|
|
5735
|
+
try {
|
|
5736
|
+
await deletePreset(id);
|
|
5737
|
+
} catch (error) {
|
|
5738
|
+
handleError(error);
|
|
5739
|
+
}
|
|
5740
|
+
});
|
|
5741
|
+
const triggers = analyze.command("triggers").description("Manage scheduled triggers on an analysis");
|
|
5742
|
+
triggers.command("list").description("List triggers for an analysis").argument("<analysisId>", "Analysis ID").action(async (analysisId, _options, cmd) => {
|
|
5743
|
+
try {
|
|
5744
|
+
await listTriggers(analysisId, cmd);
|
|
5745
|
+
} catch (error) {
|
|
5746
|
+
handleError(error);
|
|
5747
|
+
}
|
|
5748
|
+
});
|
|
5749
|
+
triggers.command("create").description("Create a trigger (ONCE: ISO-8601 timestamp; CRON: cron expression)").argument("<analysisId>", "Analysis ID").requiredOption("--kind <kind>", "ONCE or CRON").requiredOption("--schedule <spec>", "ISO-8601 timestamp (ONCE) or cron expression (CRON)").action(async (analysisId, options, cmd) => {
|
|
5750
|
+
try {
|
|
5751
|
+
await createTrigger(analysisId, options.kind, options.schedule, cmd);
|
|
5752
|
+
} catch (error) {
|
|
5753
|
+
handleError(error);
|
|
5754
|
+
}
|
|
5755
|
+
});
|
|
5756
|
+
triggers.command("delete").description("Delete a trigger").argument("<triggerId>", "Trigger ID").action(async (triggerId) => {
|
|
5757
|
+
try {
|
|
5758
|
+
await deleteTrigger(triggerId);
|
|
5759
|
+
} catch (error) {
|
|
5760
|
+
handleError(error);
|
|
5761
|
+
}
|
|
5762
|
+
});
|
|
5763
|
+
triggers.command("update").description("Update a trigger \u2014 pause/resume (--active) and/or reschedule (--schedule)").argument("<triggerId>", "Trigger ID").option("--active <bool>", "true to resume, false to pause").option("--schedule <spec>", "New schedule spec (ISO-8601 instant for ONCE, Quartz cron for CRON)").action(async (triggerId, options, cmd) => {
|
|
5764
|
+
try {
|
|
5765
|
+
await updateTriggerCmd(triggerId, options, cmd);
|
|
5766
|
+
} catch (error) {
|
|
5767
|
+
handleError(error);
|
|
5768
|
+
}
|
|
5769
|
+
});
|
|
5770
|
+
}
|
|
5771
|
+
|
|
5772
|
+
// src/commands/data-sources/index.ts
|
|
5773
|
+
import chalk26 from "chalk";
|
|
5774
|
+
function getOutputFormat16(cmd) {
|
|
5775
|
+
const config = loadConfig();
|
|
5776
|
+
const globalOpts = cmd.optsWithGlobals();
|
|
5777
|
+
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
5778
|
+
}
|
|
5779
|
+
function parseConfigPairs(pairs) {
|
|
5780
|
+
const out = {};
|
|
5781
|
+
if (!pairs) return out;
|
|
5782
|
+
for (const pair of pairs) {
|
|
5783
|
+
const idx = pair.indexOf("=");
|
|
5784
|
+
if (idx <= 0) {
|
|
5785
|
+
throw new Error(`Invalid --config "${pair}" \u2014 expected key=value.`);
|
|
5786
|
+
}
|
|
5787
|
+
const key = pair.substring(0, idx).trim();
|
|
5788
|
+
const value = pair.substring(idx + 1);
|
|
5789
|
+
if (!key) {
|
|
5790
|
+
throw new Error(`Invalid --config "${pair}" \u2014 empty key.`);
|
|
5791
|
+
}
|
|
5792
|
+
out[key] = value;
|
|
5793
|
+
}
|
|
5794
|
+
return out;
|
|
5795
|
+
}
|
|
5796
|
+
function dataSourceTableRow(ds) {
|
|
5797
|
+
return {
|
|
5798
|
+
id: ds.id,
|
|
5799
|
+
name: ds.name,
|
|
5800
|
+
type: ds.type,
|
|
5801
|
+
target: `${ds.targetEntityId}@${ds.targetEntityBranch}`,
|
|
5802
|
+
schedule: ds.scheduleCron ?? "manual",
|
|
5803
|
+
lastStatus: ds.lastRunStatus ?? "\u2014",
|
|
5804
|
+
lastRefreshAt: ds.lastRefreshAt ?? "\u2014"
|
|
5805
|
+
};
|
|
5806
|
+
}
|
|
5807
|
+
function formatBytes(bytes) {
|
|
5808
|
+
if (bytes === null || bytes === void 0) return "\u2014";
|
|
5809
|
+
if (bytes < 1e3) return `${bytes} B`;
|
|
5810
|
+
if (bytes < 1e6) return `${(bytes / 1e3).toFixed(1)} kB`;
|
|
5811
|
+
if (bytes < 1e9) return `${(bytes / 1e6).toFixed(2)} MB`;
|
|
5812
|
+
return `${(bytes / 1e9).toFixed(2)} GB`;
|
|
5813
|
+
}
|
|
5814
|
+
function formatCredits(credits) {
|
|
5815
|
+
if (credits === null || credits === void 0) return "\u2014";
|
|
5816
|
+
if (credits === 0) return "0";
|
|
5817
|
+
if (credits < 0.01) return credits.toFixed(4);
|
|
5818
|
+
return credits.toFixed(2);
|
|
5819
|
+
}
|
|
5820
|
+
function humanizeCron(cron) {
|
|
5821
|
+
if (!cron || !cron.trim()) return "manual";
|
|
5822
|
+
const parts = cron.trim().split(/\s+/);
|
|
5823
|
+
if (parts.length < 6) return cron.trim();
|
|
5824
|
+
const [sec, min, hour, dom, mon, dow] = parts;
|
|
5825
|
+
const pad2 = (n) => n.length < 2 ? `0${n}` : n;
|
|
5826
|
+
const everyDay = (dom === "*" || dom === "?") && mon === "*" && (dow === "*" || dow === "?");
|
|
5827
|
+
if (sec === "0" && min === "*" && hour === "*" && everyDay) return "every minute";
|
|
5828
|
+
if (sec === "0" && /^\d+$/.test(min) && hour === "*" && everyDay) {
|
|
5829
|
+
return min === "0" ? "hourly" : `hourly at :${pad2(min)}`;
|
|
5830
|
+
}
|
|
5831
|
+
if (sec === "0" && /^\d+$/.test(min) && /^\d+$/.test(hour) && everyDay) {
|
|
5832
|
+
if (hour === "0" && min === "0") return "daily at midnight UTC";
|
|
5833
|
+
return `daily at ${pad2(hour)}:${pad2(min)} UTC`;
|
|
5834
|
+
}
|
|
5835
|
+
return cron.trim();
|
|
5836
|
+
}
|
|
5837
|
+
function dashboardTableRow(s) {
|
|
5838
|
+
return {
|
|
5839
|
+
id: s.id,
|
|
5840
|
+
name: s.name,
|
|
5841
|
+
type: s.type,
|
|
5842
|
+
schedule: humanizeCron(s.scheduleCron),
|
|
5843
|
+
lastStatus: s.lastRunStatus ?? "\u2014",
|
|
5844
|
+
lastRunAt: s.lastRunAt ?? "\u2014",
|
|
5845
|
+
nextScheduledAt: s.nextScheduledAt ?? "\u2014",
|
|
5846
|
+
recentFailures: `${s.recentFailureCount}/${s.recentRunCount}`,
|
|
5847
|
+
lastTransferred: formatBytes(s.lastBytesFetched)
|
|
5848
|
+
};
|
|
5849
|
+
}
|
|
5850
|
+
function runTableRow(run) {
|
|
5851
|
+
return {
|
|
5852
|
+
runId: run.runId,
|
|
5853
|
+
status: run.status,
|
|
5854
|
+
startedAt: run.startedAt ?? "\u2014",
|
|
5855
|
+
finishedAt: run.finishedAt ?? "\u2014",
|
|
5856
|
+
rows: run.rowsImported !== null && run.rowsImported !== void 0 ? String(run.rowsImported) : "\u2014",
|
|
5857
|
+
transferred: formatBytes(run.bytesFetched),
|
|
5858
|
+
credits: formatCredits(run.creditsCharged),
|
|
5859
|
+
triggeredBy: run.triggeredBy ?? "\u2014"
|
|
5860
|
+
};
|
|
5861
|
+
}
|
|
5862
|
+
async function listDataSources(projectId, cmd) {
|
|
5863
|
+
const outputFormat = getOutputFormat16(cmd);
|
|
5864
|
+
const api = createApiClient();
|
|
5865
|
+
const sources = await api.storage.listDataSources(projectId);
|
|
5866
|
+
if (outputFormat === "human" && sources.length === 0) {
|
|
5867
|
+
console.log(chalk26.dim("No data sources found."));
|
|
5868
|
+
return;
|
|
5869
|
+
}
|
|
5870
|
+
format(sources.map(dataSourceTableRow), {
|
|
5871
|
+
format: outputFormat,
|
|
5872
|
+
columns: ["id", "name", "type", "target", "schedule", "lastStatus", "lastRefreshAt"]
|
|
5873
|
+
});
|
|
5874
|
+
}
|
|
5875
|
+
async function getDataSource(id, cmd) {
|
|
5876
|
+
const outputFormat = getOutputFormat16(cmd);
|
|
5877
|
+
const api = createApiClient();
|
|
5878
|
+
const ds = await api.storage.getDataSource(id);
|
|
5879
|
+
format(ds, { format: outputFormat });
|
|
5880
|
+
}
|
|
5881
|
+
async function showDashboard(projectId, cmd) {
|
|
5882
|
+
const outputFormat = getOutputFormat16(cmd);
|
|
5883
|
+
const api = createApiClient();
|
|
5884
|
+
const dashboard = await api.storage.getDataSourceDashboard(projectId);
|
|
5885
|
+
if (outputFormat !== "human") {
|
|
5886
|
+
format(dashboard, { format: outputFormat });
|
|
5887
|
+
return;
|
|
5888
|
+
}
|
|
5889
|
+
const r = dashboard.rollup;
|
|
5890
|
+
let line = chalk26.bold(`DataSources in ${projectId}: `) + `${r.totalSources} total, ${r.scheduledSources} scheduled, ${r.sourcesWithRecentFailure} failing recently`;
|
|
5891
|
+
if (r.lastActivityAt) line += `, last activity ${r.lastActivityAt}`;
|
|
5892
|
+
console.log(line);
|
|
5893
|
+
if (dashboard.sources.length === 0) {
|
|
5894
|
+
console.log(chalk26.dim("No data sources."));
|
|
5895
|
+
return;
|
|
5896
|
+
}
|
|
5897
|
+
format(dashboard.sources.map(dashboardTableRow), {
|
|
5898
|
+
format: outputFormat,
|
|
5899
|
+
columns: ["id", "name", "type", "schedule", "lastStatus", "lastRunAt", "nextScheduledAt", "recentFailures", "lastTransferred"]
|
|
5900
|
+
});
|
|
5901
|
+
}
|
|
5902
|
+
async function createDataSource(options, cmd) {
|
|
5903
|
+
const outputFormat = getOutputFormat16(cmd);
|
|
5904
|
+
const api = createApiClient();
|
|
5905
|
+
const request = {
|
|
5906
|
+
projectId: options.projectId,
|
|
5907
|
+
projectBranch: options.projectBranch,
|
|
5908
|
+
targetEntityId: options.targetEntityId,
|
|
5909
|
+
targetEntityBranch: options.targetEntityBranch,
|
|
5910
|
+
name: options.name,
|
|
5911
|
+
type: options.type,
|
|
5912
|
+
config: parseConfigPairs(options.config),
|
|
5913
|
+
scheduleCron: options.scheduleCron ?? null
|
|
5914
|
+
};
|
|
5915
|
+
const ds = await api.storage.createDataSource(request);
|
|
5916
|
+
if (outputFormat === "human") {
|
|
5917
|
+
console.log(chalk26.green(`\u2713 Created data source ${ds.id}`));
|
|
5918
|
+
console.log(chalk26.dim(` Last run: ${ds.lastRunStatus ?? "\u2014"}`));
|
|
5919
|
+
if (ds.lastRunError) console.log(chalk26.dim(` Error: ${ds.lastRunError}`));
|
|
5920
|
+
} else {
|
|
5921
|
+
format(ds, { format: outputFormat });
|
|
5922
|
+
}
|
|
5923
|
+
}
|
|
5924
|
+
async function updateDataSource(id, options, cmd) {
|
|
5925
|
+
const outputFormat = getOutputFormat16(cmd);
|
|
5926
|
+
if (options.name === void 0 && options.type === void 0 && (!options.config || options.config.length === 0) && options.scheduleCron === void 0 && !options.clearSchedule) {
|
|
5927
|
+
throw new Error("Provide at least one of --name, --type, --config, --schedule-cron, or --clear-schedule.");
|
|
5928
|
+
}
|
|
5929
|
+
if (options.scheduleCron !== void 0 && options.clearSchedule) {
|
|
5930
|
+
throw new Error("--schedule-cron and --clear-schedule are mutually exclusive.");
|
|
5931
|
+
}
|
|
5932
|
+
let scheduleCron;
|
|
5933
|
+
if (options.clearSchedule) {
|
|
5934
|
+
scheduleCron = "";
|
|
5935
|
+
} else if (options.scheduleCron !== void 0) {
|
|
5936
|
+
scheduleCron = options.scheduleCron;
|
|
5937
|
+
} else {
|
|
5938
|
+
scheduleCron = null;
|
|
5939
|
+
}
|
|
5940
|
+
const request = {
|
|
5941
|
+
name: options.name ?? null,
|
|
5942
|
+
type: options.type ?? null,
|
|
5943
|
+
config: options.config && options.config.length > 0 ? parseConfigPairs(options.config) : null,
|
|
5944
|
+
scheduleCron
|
|
5945
|
+
};
|
|
5946
|
+
const api = createApiClient();
|
|
5947
|
+
const ds = await api.storage.updateDataSource(id, request);
|
|
5948
|
+
if (outputFormat === "human") {
|
|
5949
|
+
console.log(chalk26.green(`\u2713 Updated data source ${ds.id}`));
|
|
5950
|
+
} else {
|
|
5951
|
+
format(ds, { format: outputFormat });
|
|
5952
|
+
}
|
|
5953
|
+
}
|
|
5954
|
+
async function deleteDataSource(id) {
|
|
5955
|
+
const api = createApiClient();
|
|
5956
|
+
await api.storage.deleteDataSource(id);
|
|
5957
|
+
console.log(chalk26.green(`\u2713 Deleted data source ${id}`));
|
|
5958
|
+
}
|
|
5959
|
+
async function refreshDataSource(id, cmd) {
|
|
5960
|
+
const outputFormat = getOutputFormat16(cmd);
|
|
5961
|
+
const api = createApiClient();
|
|
5962
|
+
const run = await api.storage.refreshDataSource(id);
|
|
5963
|
+
if (outputFormat === "human") {
|
|
5964
|
+
console.log(chalk26.green(`\u2713 Refresh queued \u2014 run ${run.runId}, status ${run.status}`));
|
|
5965
|
+
if (run.errorMessage) console.log(chalk26.red(` Error: ${run.errorMessage}`));
|
|
5966
|
+
} else {
|
|
5967
|
+
format(run, { format: outputFormat });
|
|
5968
|
+
}
|
|
5969
|
+
}
|
|
5970
|
+
async function listRuns2(id, limit, cmd) {
|
|
5971
|
+
const outputFormat = getOutputFormat16(cmd);
|
|
5972
|
+
const api = createApiClient();
|
|
5973
|
+
const runs = await api.storage.listDataSourceRuns(id, limit);
|
|
5974
|
+
if (outputFormat === "human" && runs.length === 0) {
|
|
5975
|
+
console.log(chalk26.dim("No runs yet."));
|
|
5976
|
+
return;
|
|
5977
|
+
}
|
|
5978
|
+
format(runs.map(runTableRow), {
|
|
5979
|
+
format: outputFormat,
|
|
5980
|
+
columns: ["runId", "status", "startedAt", "finishedAt", "rows", "transferred", "credits", "triggeredBy"]
|
|
4840
5981
|
});
|
|
4841
|
-
|
|
4842
|
-
|
|
4843
|
-
|
|
4844
|
-
|
|
4845
|
-
|
|
4846
|
-
|
|
4847
|
-
|
|
4848
|
-
|
|
4849
|
-
|
|
4850
|
-
|
|
4851
|
-
|
|
5982
|
+
}
|
|
5983
|
+
async function getRun(id, runId, cmd) {
|
|
5984
|
+
const outputFormat = getOutputFormat16(cmd);
|
|
5985
|
+
const api = createApiClient();
|
|
5986
|
+
const run = await api.storage.getDataSourceRun(id, runId);
|
|
5987
|
+
format(run, { format: outputFormat });
|
|
5988
|
+
}
|
|
5989
|
+
async function listConnectorTypes(cmd) {
|
|
5990
|
+
const outputFormat = getOutputFormat16(cmd);
|
|
5991
|
+
const api = createApiClient();
|
|
5992
|
+
const types = await api.storage.listDataSourceConnectorTypes();
|
|
5993
|
+
if (outputFormat === "human") {
|
|
5994
|
+
if (types.length === 0) {
|
|
5995
|
+
console.log(chalk26.dim("No connector types registered."));
|
|
5996
|
+
return;
|
|
4852
5997
|
}
|
|
4853
|
-
|
|
4854
|
-
|
|
5998
|
+
for (const t of types) console.log(t);
|
|
5999
|
+
} else {
|
|
6000
|
+
format(types, { format: outputFormat });
|
|
6001
|
+
}
|
|
6002
|
+
}
|
|
6003
|
+
function registerDataSourcesCommands(program) {
|
|
6004
|
+
const dataSources = program.command("data-sources").description("Manage scheduled DataSource imports (Google Sheets, S3 URL, JDBC)");
|
|
6005
|
+
dataSources.command("list").description("List data sources (optionally scoped to a project)").option("--project-id <id>", "Filter by project ID").action(async (options, cmd) => {
|
|
4855
6006
|
try {
|
|
4856
|
-
await
|
|
4857
|
-
id,
|
|
4858
|
-
text,
|
|
4859
|
-
(api, aid, v) => api.analysis.patchDescription(aid, { description: v === "" ? null : v }),
|
|
4860
|
-
"Description",
|
|
4861
|
-
cmd
|
|
4862
|
-
);
|
|
6007
|
+
await listDataSources(options.projectId, cmd);
|
|
4863
6008
|
} catch (error) {
|
|
4864
6009
|
handleError(error);
|
|
4865
6010
|
}
|
|
4866
6011
|
});
|
|
4867
|
-
|
|
6012
|
+
dataSources.command("dashboard").description("Project-level rollup: per-source last-run status, next-scheduled, recent failures").requiredOption("--project-id <id>", "Project ID").action(async (options, cmd) => {
|
|
4868
6013
|
try {
|
|
4869
|
-
|
|
4870
|
-
await patchAndPrint(
|
|
4871
|
-
id,
|
|
4872
|
-
visibility,
|
|
4873
|
-
(api, aid, v) => api.analysis.patchVisibility(aid, { visibility: v }),
|
|
4874
|
-
"Visibility",
|
|
4875
|
-
cmd
|
|
4876
|
-
);
|
|
6014
|
+
await showDashboard(options.projectId, cmd);
|
|
4877
6015
|
} catch (error) {
|
|
4878
6016
|
handleError(error);
|
|
4879
6017
|
}
|
|
4880
6018
|
});
|
|
4881
|
-
|
|
6019
|
+
dataSources.command("get").description("Show one data source").argument("<id>", "Data source ID (UUID)").action(async (id, _options, cmd) => {
|
|
4882
6020
|
try {
|
|
4883
|
-
await
|
|
4884
|
-
id,
|
|
4885
|
-
markdown,
|
|
4886
|
-
(api, aid, v) => api.analysis.patchIntroduction(aid, { introduction: v === "" ? null : v }),
|
|
4887
|
-
"Introduction",
|
|
4888
|
-
cmd
|
|
4889
|
-
);
|
|
6021
|
+
await getDataSource(id, cmd);
|
|
4890
6022
|
} catch (error) {
|
|
4891
6023
|
handleError(error);
|
|
4892
6024
|
}
|
|
4893
6025
|
});
|
|
4894
|
-
|
|
6026
|
+
dataSources.command("create").description("Create a data source (runs the initial fetch synchronously)").requiredOption("--project-id <id>", "Project ID").requiredOption("--project-branch <branch>", 'Project branch (usually "main")').requiredOption("--target-entity-id <id>", "Target table entity ID").requiredOption("--target-entity-branch <branch>", "Target table entity branch").requiredOption("--name <name>", "Display name").requiredOption("--type <type>", "Connector type (google_sheets, s3_url, jdbc)").option("--config <key=value>", "Connector config field \u2014 repeat for multiple", (value, prev = []) => prev.concat([value]), []).option("--schedule-cron <expr>", 'Quartz cron expression (e.g. "0 0 2 * * ?" for daily 02:00 UTC); omit for manual-only').action(async (options, cmd) => {
|
|
4895
6027
|
try {
|
|
4896
|
-
await
|
|
4897
|
-
id,
|
|
4898
|
-
hours,
|
|
4899
|
-
(api, aid, v) => api.analysis.patchHours(aid, { hours: v }),
|
|
4900
|
-
"Hours",
|
|
4901
|
-
cmd
|
|
4902
|
-
);
|
|
6028
|
+
await createDataSource(options, cmd);
|
|
4903
6029
|
} catch (error) {
|
|
4904
6030
|
handleError(error);
|
|
4905
6031
|
}
|
|
4906
6032
|
});
|
|
4907
|
-
|
|
6033
|
+
dataSources.command("update").description("Update a data source (omit a flag to leave that field unchanged)").argument("<id>", "Data source ID").option("--name <name>", "New display name").option("--type <type>", "New connector type").option("--config <key=value>", 'Replace the entire config map \u2014 repeat for multiple. Send "[redacted]" as a value to keep the existing encrypted credential.', (value, prev = []) => prev.concat([value]), []).option("--schedule-cron <expr>", "New Quartz cron expression").option("--clear-schedule", "Switch this data source to manual-only").action(async (id, options, cmd) => {
|
|
4908
6034
|
try {
|
|
4909
|
-
await
|
|
4910
|
-
id,
|
|
4911
|
-
credits,
|
|
4912
|
-
(api, aid, v) => api.analysis.patchBudget(aid, { budget: v }),
|
|
4913
|
-
"Budget",
|
|
4914
|
-
cmd
|
|
4915
|
-
);
|
|
6035
|
+
await updateDataSource(id, options, cmd);
|
|
4916
6036
|
} catch (error) {
|
|
4917
6037
|
handleError(error);
|
|
4918
6038
|
}
|
|
4919
6039
|
});
|
|
4920
|
-
|
|
6040
|
+
dataSources.command("delete").description("Delete a data source (existing imported rows are kept)").argument("<id>", "Data source ID").action(async (id) => {
|
|
4921
6041
|
try {
|
|
4922
|
-
|
|
4923
|
-
await patchAndPrint(
|
|
4924
|
-
id,
|
|
4925
|
-
csv,
|
|
4926
|
-
(api, aid) => api.analysis.patchTargets(aid, { targets }),
|
|
4927
|
-
"Targets",
|
|
4928
|
-
cmd
|
|
4929
|
-
);
|
|
6042
|
+
await deleteDataSource(id);
|
|
4930
6043
|
} catch (error) {
|
|
4931
6044
|
handleError(error);
|
|
4932
6045
|
}
|
|
4933
6046
|
});
|
|
4934
|
-
|
|
6047
|
+
dataSources.command("refresh").description("Trigger an out-of-schedule refresh now").argument("<id>", "Data source ID").action(async (id, _options, cmd) => {
|
|
4935
6048
|
try {
|
|
4936
|
-
|
|
4937
|
-
await patchAndPrint(
|
|
4938
|
-
id,
|
|
4939
|
-
csv,
|
|
4940
|
-
(api, aid) => api.analysis.patchQuestions(aid, { questions }),
|
|
4941
|
-
"Questions",
|
|
4942
|
-
cmd
|
|
4943
|
-
);
|
|
6049
|
+
await refreshDataSource(id, cmd);
|
|
4944
6050
|
} catch (error) {
|
|
4945
6051
|
handleError(error);
|
|
4946
6052
|
}
|
|
4947
6053
|
});
|
|
4948
|
-
|
|
6054
|
+
dataSources.command("runs").description("List recent runs for a data source (newest first)").argument("<id>", "Data source ID").option("--limit <n>", "Max number of runs to show", "20").action(async (id, options, cmd) => {
|
|
4949
6055
|
try {
|
|
4950
|
-
await
|
|
4951
|
-
id,
|
|
4952
|
-
name,
|
|
4953
|
-
(api, aid, v) => api.analysis.patchSegment(aid, { segment: v === "" ? null : v }),
|
|
4954
|
-
"Segment",
|
|
4955
|
-
cmd
|
|
4956
|
-
);
|
|
6056
|
+
await listRuns2(id, parseInt(options.limit, 10), cmd);
|
|
4957
6057
|
} catch (error) {
|
|
4958
6058
|
handleError(error);
|
|
4959
6059
|
}
|
|
4960
6060
|
});
|
|
4961
|
-
|
|
6061
|
+
dataSources.command("run").description("Show one run").argument("<id>", "Data source ID").argument("<runId>", "Run ID").action(async (id, runId, _options, cmd) => {
|
|
4962
6062
|
try {
|
|
4963
|
-
await
|
|
6063
|
+
await getRun(id, runId, cmd);
|
|
4964
6064
|
} catch (error) {
|
|
4965
6065
|
handleError(error);
|
|
4966
6066
|
}
|
|
4967
6067
|
});
|
|
4968
|
-
|
|
6068
|
+
dataSources.command("types").description("List registered connector types").action(async (_options, cmd) => {
|
|
4969
6069
|
try {
|
|
4970
|
-
await
|
|
6070
|
+
await listConnectorTypes(cmd);
|
|
4971
6071
|
} catch (error) {
|
|
4972
6072
|
handleError(error);
|
|
4973
6073
|
}
|
|
4974
6074
|
});
|
|
4975
|
-
|
|
6075
|
+
}
|
|
6076
|
+
|
|
6077
|
+
// src/commands/table-exporters/index.ts
|
|
6078
|
+
import chalk27 from "chalk";
|
|
6079
|
+
function getOutputFormat17(cmd) {
|
|
6080
|
+
const config = loadConfig();
|
|
6081
|
+
const globalOpts = cmd.optsWithGlobals();
|
|
6082
|
+
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
6083
|
+
}
|
|
6084
|
+
function registerTableExportersCommands(program) {
|
|
6085
|
+
const exporters = program.command("table-exporters").description("Manage user-defined exporters (UDE) \u2014 admin-only");
|
|
6086
|
+
exporters.command("list").description("List all registered user-defined exporters").action(async (_options, cmd) => {
|
|
4976
6087
|
try {
|
|
4977
|
-
|
|
6088
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
6089
|
+
const api = createApiClient();
|
|
6090
|
+
const list = await api.storage.listUserDefinedExporters();
|
|
6091
|
+
if (outputFormat === "json") {
|
|
6092
|
+
format(list, { format: outputFormat });
|
|
6093
|
+
return;
|
|
6094
|
+
}
|
|
6095
|
+
const rows = list.map((e) => ({
|
|
6096
|
+
id: e.id ?? "",
|
|
6097
|
+
name: e.name,
|
|
6098
|
+
format: e.format,
|
|
6099
|
+
extension: e.extension ?? "",
|
|
6100
|
+
mimeType: e.mimeType ?? "",
|
|
6101
|
+
priority: e.priority ?? 50,
|
|
6102
|
+
function: `${e.functionProjectId}/${e.functionEntityId}`,
|
|
6103
|
+
createdBy: e.createdBy ?? ""
|
|
6104
|
+
}));
|
|
6105
|
+
format(rows, {
|
|
6106
|
+
format: outputFormat,
|
|
6107
|
+
columns: ["id", "name", "format", "extension", "mimeType", "priority", "function", "createdBy"]
|
|
6108
|
+
});
|
|
6109
|
+
console.log(chalk27.dim(`${list.length} exporter(s)`));
|
|
4978
6110
|
} catch (error) {
|
|
4979
6111
|
handleError(error);
|
|
4980
6112
|
}
|
|
4981
6113
|
});
|
|
4982
|
-
|
|
6114
|
+
exporters.command("get").description("Show a single user-defined exporter by id").argument("<id>", "Exporter id").action(async (id, _options, cmd) => {
|
|
4983
6115
|
try {
|
|
4984
|
-
|
|
6116
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
6117
|
+
const api = createApiClient();
|
|
6118
|
+
const list = await api.storage.listUserDefinedExporters();
|
|
6119
|
+
const exporter = list.find((e) => e.id === id);
|
|
6120
|
+
if (!exporter) {
|
|
6121
|
+
console.error(chalk27.red(`No exporter with id="${id}".`));
|
|
6122
|
+
process.exit(1);
|
|
6123
|
+
}
|
|
6124
|
+
format(exporter, { format: outputFormat });
|
|
4985
6125
|
} catch (error) {
|
|
4986
6126
|
handleError(error);
|
|
4987
6127
|
}
|
|
4988
6128
|
});
|
|
4989
|
-
|
|
4990
|
-
presets.command("list").description("List your analysis presets").action(async (_options, cmd) => {
|
|
6129
|
+
exporters.command("create").description("Register a new user-defined exporter").requiredOption("--name <name>", 'Display name (e.g. "Acme machine instrument export")').requiredOption("--format <token>", 'Format token used in the dispatch URL (e.g. "acme")').requiredOption("--function-project <id>", "Function entity's project id").requiredOption("--function-entity <id>", "Function entity id").option("--description <text>", "Free-form description").option("--extension <ext>", 'Filename extension (must start with ".")').option("--mime-type <mime>", "MIME type the function produces").option("--function-project-branch <branch>", "Function project branch", "main").option("--function-entity-branch <branch>", "Function entity branch", "main").option("--priority <n>", "Dispatch priority (default 50; > 200 overrides built-ins)", "50").action(async (options, cmd) => {
|
|
4991
6130
|
try {
|
|
4992
|
-
|
|
6131
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
6132
|
+
const api = createApiClient();
|
|
6133
|
+
const payload = {
|
|
6134
|
+
name: options.name,
|
|
6135
|
+
description: options.description,
|
|
6136
|
+
format: options.format,
|
|
6137
|
+
extension: options.extension,
|
|
6138
|
+
mimeType: options.mimeType,
|
|
6139
|
+
functionProjectId: options.functionProject,
|
|
6140
|
+
functionProjectBranch: options.functionProjectBranch,
|
|
6141
|
+
functionEntityId: options.functionEntity,
|
|
6142
|
+
functionEntityBranch: options.functionEntityBranch,
|
|
6143
|
+
priority: Number(options.priority)
|
|
6144
|
+
};
|
|
6145
|
+
const created = await api.storage.registerUserDefinedExporter(payload);
|
|
6146
|
+
if (outputFormat === "json") {
|
|
6147
|
+
format(created, { format: outputFormat });
|
|
6148
|
+
return;
|
|
6149
|
+
}
|
|
6150
|
+
console.log(chalk27.green(`Registered exporter "${created.name}" (id=${created.id}, format=${created.format})`));
|
|
4993
6151
|
} catch (error) {
|
|
4994
6152
|
handleError(error);
|
|
4995
6153
|
}
|
|
4996
6154
|
});
|
|
4997
|
-
|
|
6155
|
+
exporters.command("delete").description("Delete a user-defined exporter").argument("<id>", "Exporter id").action(async (id) => {
|
|
4998
6156
|
try {
|
|
4999
|
-
|
|
6157
|
+
const api = createApiClient();
|
|
6158
|
+
await api.storage.deleteUserDefinedExporter(id);
|
|
6159
|
+
console.log(chalk27.green(`Deleted exporter id=${id}`));
|
|
5000
6160
|
} catch (error) {
|
|
5001
6161
|
handleError(error);
|
|
5002
6162
|
}
|
|
5003
6163
|
});
|
|
5004
|
-
|
|
5005
|
-
|
|
5006
|
-
|
|
5007
|
-
|
|
5008
|
-
|
|
6164
|
+
}
|
|
6165
|
+
|
|
6166
|
+
// src/commands/skeleton/index.ts
|
|
6167
|
+
import chalk28 from "chalk";
|
|
6168
|
+
import * as fs9 from "fs";
|
|
6169
|
+
function getOutputFormat18(cmd) {
|
|
6170
|
+
const config = loadConfig();
|
|
6171
|
+
const globalOpts = cmd.optsWithGlobals();
|
|
6172
|
+
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
6173
|
+
}
|
|
6174
|
+
function resolveProjectId(localOption, cmd) {
|
|
6175
|
+
if (localOption) return localOption;
|
|
6176
|
+
const globalOpts = cmd.optsWithGlobals();
|
|
6177
|
+
if (globalOpts.project) return globalOpts.project;
|
|
6178
|
+
const config = loadConfig();
|
|
6179
|
+
if (config.defaults.project) return config.defaults.project;
|
|
6180
|
+
throw new Error(
|
|
6181
|
+
"No project specified. Pass --project <id>, set the global --project flag, or run `diafunc config defaults project <id>`."
|
|
6182
|
+
);
|
|
6183
|
+
}
|
|
6184
|
+
function resolveTemplate(raw) {
|
|
6185
|
+
if (raw.startsWith("@@")) {
|
|
6186
|
+
return raw.substring(1);
|
|
6187
|
+
}
|
|
6188
|
+
if (raw.startsWith("@")) {
|
|
6189
|
+
const file = raw.substring(1);
|
|
6190
|
+
if (!file) {
|
|
6191
|
+
throw new Error("--template @ requires a filename after the @, e.g. --template @template.txt");
|
|
5009
6192
|
}
|
|
6193
|
+
if (!fs9.existsSync(file)) {
|
|
6194
|
+
throw new Error(`Template file not found: ${file}`);
|
|
6195
|
+
}
|
|
6196
|
+
return fs9.readFileSync(file, "utf-8").trim();
|
|
6197
|
+
}
|
|
6198
|
+
return raw;
|
|
6199
|
+
}
|
|
6200
|
+
function parseWeight(raw) {
|
|
6201
|
+
if (raw === void 0) return null;
|
|
6202
|
+
const value = Number(raw);
|
|
6203
|
+
if (!Number.isFinite(value) || value <= 0) {
|
|
6204
|
+
throw new Error(`Invalid --weight "${raw}" \u2014 must be a positive number.`);
|
|
6205
|
+
}
|
|
6206
|
+
return value;
|
|
6207
|
+
}
|
|
6208
|
+
function skeletonTableRow(s) {
|
|
6209
|
+
return {
|
|
6210
|
+
id: s.id,
|
|
6211
|
+
name: s.name,
|
|
6212
|
+
template: s.template,
|
|
6213
|
+
paramCount: String(s.paramCount),
|
|
6214
|
+
weight: s.weight.toFixed(2),
|
|
6215
|
+
createdAt: s.createdAt ?? "\u2014"
|
|
6216
|
+
};
|
|
6217
|
+
}
|
|
6218
|
+
async function createSkeleton(options, cmd) {
|
|
6219
|
+
const outputFormat = getOutputFormat18(cmd);
|
|
6220
|
+
const projectId = resolveProjectId(options.project, cmd);
|
|
6221
|
+
const template = resolveTemplate(options.template);
|
|
6222
|
+
const weight = parseWeight(options.weight);
|
|
6223
|
+
const request = {
|
|
6224
|
+
projectId,
|
|
6225
|
+
projectBranch: options.branch,
|
|
6226
|
+
name: options.name,
|
|
6227
|
+
template,
|
|
6228
|
+
weight
|
|
6229
|
+
};
|
|
6230
|
+
const api = createApiClient();
|
|
6231
|
+
const skeleton = await api.storage.createSkeleton(request);
|
|
6232
|
+
if (outputFormat === "human") {
|
|
6233
|
+
console.log(chalk28.green(`\u2713 Created skeleton ${skeleton.id}`));
|
|
6234
|
+
console.log(chalk28.dim(` name: ${skeleton.name}`));
|
|
6235
|
+
console.log(chalk28.dim(` template: ${skeleton.template}`));
|
|
6236
|
+
console.log(chalk28.dim(` paramCount: ${skeleton.paramCount}`));
|
|
6237
|
+
console.log(chalk28.dim(` weight: ${skeleton.weight}`));
|
|
6238
|
+
} else {
|
|
6239
|
+
format(skeleton, { format: outputFormat });
|
|
6240
|
+
}
|
|
6241
|
+
}
|
|
6242
|
+
async function listSkeletons(localProject, cmd) {
|
|
6243
|
+
const outputFormat = getOutputFormat18(cmd);
|
|
6244
|
+
const projectId = resolveProjectId(localProject, cmd);
|
|
6245
|
+
const api = createApiClient();
|
|
6246
|
+
const skeletons = await api.storage.listSkeletons(projectId);
|
|
6247
|
+
if (outputFormat === "human" && skeletons.length === 0) {
|
|
6248
|
+
console.log(chalk28.dim(`No skeletons in project ${projectId}.`));
|
|
6249
|
+
return;
|
|
6250
|
+
}
|
|
6251
|
+
format(skeletons.map(skeletonTableRow), {
|
|
6252
|
+
format: outputFormat,
|
|
6253
|
+
columns: ["id", "name", "template", "paramCount", "weight", "createdAt"]
|
|
5010
6254
|
});
|
|
5011
|
-
|
|
6255
|
+
}
|
|
6256
|
+
async function getSkeleton(id, cmd) {
|
|
6257
|
+
const outputFormat = getOutputFormat18(cmd);
|
|
6258
|
+
const api = createApiClient();
|
|
6259
|
+
const skeleton = await api.storage.getSkeleton(id);
|
|
6260
|
+
format(skeleton, { format: outputFormat });
|
|
6261
|
+
}
|
|
6262
|
+
async function updateSkeleton(id, options, cmd) {
|
|
6263
|
+
const outputFormat = getOutputFormat18(cmd);
|
|
6264
|
+
if (options.name === void 0 && options.template === void 0 && options.weight === void 0) {
|
|
6265
|
+
throw new Error("Provide at least one of --name, --template, --weight.");
|
|
6266
|
+
}
|
|
6267
|
+
const request = {
|
|
6268
|
+
name: options.name ?? null,
|
|
6269
|
+
template: options.template !== void 0 ? resolveTemplate(options.template) : null,
|
|
6270
|
+
weight: parseWeight(options.weight)
|
|
6271
|
+
};
|
|
6272
|
+
const api = createApiClient();
|
|
6273
|
+
const skeleton = await api.storage.updateSkeleton(id, request);
|
|
6274
|
+
if (outputFormat === "human") {
|
|
6275
|
+
console.log(chalk28.green(`\u2713 Updated skeleton ${skeleton.id}`));
|
|
6276
|
+
console.log(chalk28.dim(` name: ${skeleton.name}`));
|
|
6277
|
+
console.log(chalk28.dim(` template: ${skeleton.template}`));
|
|
6278
|
+
console.log(chalk28.dim(` paramCount: ${skeleton.paramCount}`));
|
|
6279
|
+
console.log(chalk28.dim(` weight: ${skeleton.weight}`));
|
|
6280
|
+
} else {
|
|
6281
|
+
format(skeleton, { format: outputFormat });
|
|
6282
|
+
}
|
|
6283
|
+
}
|
|
6284
|
+
async function deleteSkeleton(id) {
|
|
6285
|
+
const api = createApiClient();
|
|
6286
|
+
await api.storage.deleteSkeleton(id);
|
|
6287
|
+
console.log(chalk28.green(`\u2713 Deleted skeleton ${id}`));
|
|
6288
|
+
}
|
|
6289
|
+
function registerSkeletonCommands(program) {
|
|
6290
|
+
const skeleton = program.command("skeleton").description("Manage user-provided skeleton templates (project-scoped, capped at 100/project)");
|
|
6291
|
+
skeleton.command("create").description("Create a skeleton. Parse errors from the engine are surfaced as stderr.").requiredOption("--name <name>", "Display name").requiredOption(
|
|
6292
|
+
"--template <expr>",
|
|
6293
|
+
'Skeleton template expression (e.g. "?*x+?"). Use "@file.txt" to read from a file; "@@\u2026" escapes a literal leading @.'
|
|
6294
|
+
).option("--project <id>", "Project ID (defaults to global --project / config defaults.project)").option("--branch <branch>", "Project branch", "main").option("--weight <number>", "Sampling weight (positive; server default applies if omitted)").action(async (options, cmd) => {
|
|
5012
6295
|
try {
|
|
5013
|
-
await
|
|
6296
|
+
await createSkeleton(options, cmd);
|
|
5014
6297
|
} catch (error) {
|
|
5015
6298
|
handleError(error);
|
|
5016
6299
|
}
|
|
5017
6300
|
});
|
|
5018
|
-
|
|
5019
|
-
triggers.command("list").description("List triggers for an analysis").argument("<analysisId>", "Analysis ID").action(async (analysisId, _options, cmd) => {
|
|
6301
|
+
skeleton.command("list").description("List skeletons in a project").option("--project <id>", "Project ID (defaults to global --project / config defaults.project)").action(async (options, cmd) => {
|
|
5020
6302
|
try {
|
|
5021
|
-
await
|
|
6303
|
+
await listSkeletons(options.project, cmd);
|
|
5022
6304
|
} catch (error) {
|
|
5023
6305
|
handleError(error);
|
|
5024
6306
|
}
|
|
5025
6307
|
});
|
|
5026
|
-
|
|
6308
|
+
skeleton.command("get").description("Show one skeleton").argument("<id>", "Skeleton ID (UUID)").action(async (id, _options, cmd) => {
|
|
5027
6309
|
try {
|
|
5028
|
-
await
|
|
6310
|
+
await getSkeleton(id, cmd);
|
|
5029
6311
|
} catch (error) {
|
|
5030
6312
|
handleError(error);
|
|
5031
6313
|
}
|
|
5032
6314
|
});
|
|
5033
|
-
|
|
6315
|
+
skeleton.command("update").description("Update a skeleton (omit a flag to leave that field unchanged)").argument("<id>", "Skeleton ID").option("--name <name>", "New display name").option("--template <expr>", 'New template expression (supports the same "@file.txt" sugar as create)').option("--weight <number>", "New sampling weight (positive)").action(async (id, options, cmd) => {
|
|
5034
6316
|
try {
|
|
5035
|
-
await
|
|
6317
|
+
await updateSkeleton(id, options, cmd);
|
|
5036
6318
|
} catch (error) {
|
|
5037
6319
|
handleError(error);
|
|
5038
6320
|
}
|
|
5039
6321
|
});
|
|
5040
|
-
|
|
6322
|
+
skeleton.command("delete").description("Delete a skeleton").argument("<id>", "Skeleton ID").action(async (id) => {
|
|
5041
6323
|
try {
|
|
5042
|
-
await
|
|
6324
|
+
await deleteSkeleton(id);
|
|
5043
6325
|
} catch (error) {
|
|
5044
6326
|
handleError(error);
|
|
5045
6327
|
}
|
|
@@ -5300,7 +6582,7 @@ function registerCompletionCommand(program) {
|
|
|
5300
6582
|
}
|
|
5301
6583
|
|
|
5302
6584
|
// src/commands/whoami/index.ts
|
|
5303
|
-
import
|
|
6585
|
+
import chalk29 from "chalk";
|
|
5304
6586
|
function registerWhoamiCommand(program) {
|
|
5305
6587
|
program.command("whoami").description("Show the currently authenticated user").action(async (_options, cmd) => {
|
|
5306
6588
|
try {
|
|
@@ -5310,8 +6592,8 @@ function registerWhoamiCommand(program) {
|
|
|
5310
6592
|
const api = createApiClient();
|
|
5311
6593
|
const user = await api.admin.getMyUser();
|
|
5312
6594
|
if (outputFormat === "human") {
|
|
5313
|
-
console.log(
|
|
5314
|
-
console.log(
|
|
6595
|
+
console.log(chalk29.bold(user.name) + chalk29.dim(` <${user.email}>`));
|
|
6596
|
+
console.log(chalk29.dim(` Role: ${user.role} \xB7 Remaining credits: ${user.remainingCredits} \xB7 Profile: ${config.currentProfile}`));
|
|
5315
6597
|
} else {
|
|
5316
6598
|
format(user, { format: outputFormat });
|
|
5317
6599
|
}
|
|
@@ -5322,8 +6604,8 @@ function registerWhoamiCommand(program) {
|
|
|
5322
6604
|
}
|
|
5323
6605
|
|
|
5324
6606
|
// src/commands/utilization/index.ts
|
|
5325
|
-
import
|
|
5326
|
-
function
|
|
6607
|
+
import chalk30 from "chalk";
|
|
6608
|
+
function getOutputFormat19(cmd) {
|
|
5327
6609
|
const config = loadConfig();
|
|
5328
6610
|
const globalOpts = cmd.optsWithGlobals();
|
|
5329
6611
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -5331,27 +6613,27 @@ function getOutputFormat15(cmd) {
|
|
|
5331
6613
|
function printUtilizationHuman(u, label) {
|
|
5332
6614
|
const when = u.day !== null && u.day !== void 0 ? `${u.year}-${String(u.month).padStart(2, "0")}-${String(u.day).padStart(2, "0")}` : `${u.year}-${String(u.month).padStart(2, "0")}`;
|
|
5333
6615
|
if (label) {
|
|
5334
|
-
console.log(
|
|
6616
|
+
console.log(chalk30.bold(label) + " " + chalk30.dim(when));
|
|
5335
6617
|
} else {
|
|
5336
|
-
console.log(
|
|
6618
|
+
console.log(chalk30.bold(when));
|
|
5337
6619
|
}
|
|
5338
6620
|
if (u.types.length === 0) {
|
|
5339
|
-
console.log(
|
|
6621
|
+
console.log(chalk30.dim(" (no usage)"));
|
|
5340
6622
|
return;
|
|
5341
6623
|
}
|
|
5342
6624
|
for (const t of u.types) {
|
|
5343
6625
|
console.log(
|
|
5344
|
-
` ${t.type.padEnd(24)} ${
|
|
6626
|
+
` ${t.type.padEnd(24)} ${chalk30.cyan(String(t.quantity).padStart(10))} ${chalk30.dim("credits:")} ${t.credits.toFixed(2)}`
|
|
5345
6627
|
);
|
|
5346
6628
|
}
|
|
5347
6629
|
const total = u.totalCredits ?? u.types.reduce((s, t) => s + t.credits, 0);
|
|
5348
|
-
console.log(
|
|
6630
|
+
console.log(chalk30.bold(` Total credits: ${total.toFixed(2)}`));
|
|
5349
6631
|
}
|
|
5350
6632
|
function registerUtilizationCommand(program) {
|
|
5351
6633
|
const util = program.command("utilization").description("Show credit utilization");
|
|
5352
6634
|
util.command("actual", { isDefault: true }).description("Show current utilization (default subcommand)").action(async (_options, cmd) => {
|
|
5353
6635
|
try {
|
|
5354
|
-
const outputFormat =
|
|
6636
|
+
const outputFormat = getOutputFormat19(cmd);
|
|
5355
6637
|
const api = createApiClient();
|
|
5356
6638
|
const utilization = await api.admin.getActualUtilization();
|
|
5357
6639
|
if (outputFormat === "human") {
|
|
@@ -5365,12 +6647,12 @@ function registerUtilizationCommand(program) {
|
|
|
5365
6647
|
});
|
|
5366
6648
|
util.command("history").description("Show utilization history").action(async (_options, cmd) => {
|
|
5367
6649
|
try {
|
|
5368
|
-
const outputFormat =
|
|
6650
|
+
const outputFormat = getOutputFormat19(cmd);
|
|
5369
6651
|
const api = createApiClient();
|
|
5370
6652
|
const history = await api.admin.getUtilizationHistory();
|
|
5371
6653
|
if (outputFormat === "human") {
|
|
5372
6654
|
if (history.length === 0) {
|
|
5373
|
-
console.log(
|
|
6655
|
+
console.log(chalk30.dim("No usage recorded."));
|
|
5374
6656
|
return;
|
|
5375
6657
|
}
|
|
5376
6658
|
for (const u of history) {
|
|
@@ -5387,13 +6669,13 @@ function registerUtilizationCommand(program) {
|
|
|
5387
6669
|
}
|
|
5388
6670
|
|
|
5389
6671
|
// src/commands/entity-branch/index.ts
|
|
5390
|
-
import
|
|
5391
|
-
function
|
|
6672
|
+
import chalk31 from "chalk";
|
|
6673
|
+
function getOutputFormat20(cmd) {
|
|
5392
6674
|
const config = loadConfig();
|
|
5393
6675
|
const globalOpts = cmd.optsWithGlobals();
|
|
5394
6676
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
5395
6677
|
}
|
|
5396
|
-
function
|
|
6678
|
+
function getOverrides11(cmd) {
|
|
5397
6679
|
const opts = cmd.optsWithGlobals();
|
|
5398
6680
|
return { project: opts.project, branch: opts.branch };
|
|
5399
6681
|
}
|
|
@@ -5401,8 +6683,8 @@ function registerEntityBranchCommands(program) {
|
|
|
5401
6683
|
const eb = program.command("entity-branch").description("Manage entity branches (parallel versions of a single entity)");
|
|
5402
6684
|
eb.command("list").description("List branches of an entity").argument("<ref>", "Entity reference (projectId/branch/entityId)").action(async (ref, _options, cmd) => {
|
|
5403
6685
|
try {
|
|
5404
|
-
const outputFormat =
|
|
5405
|
-
const overrides =
|
|
6686
|
+
const outputFormat = getOutputFormat20(cmd);
|
|
6687
|
+
const overrides = getOverrides11(cmd);
|
|
5406
6688
|
const resolved = parseEntityReference(ref, overrides);
|
|
5407
6689
|
const api = createApiClient();
|
|
5408
6690
|
const branches = await api.storage.getEntityBranches(
|
|
@@ -5421,7 +6703,7 @@ function registerEntityBranchCommands(program) {
|
|
|
5421
6703
|
});
|
|
5422
6704
|
eb.command("create").description("Create a new branch of an entity from an existing branch").argument("<ref>", "Source entity reference (projectId/branch/entityId/sourceBranch)").argument("<targetBranch>", "New branch name").action(async (ref, targetBranch, _options, cmd) => {
|
|
5423
6705
|
try {
|
|
5424
|
-
const overrides =
|
|
6706
|
+
const overrides = getOverrides11(cmd);
|
|
5425
6707
|
const resolved = parseEntityReference(ref, overrides);
|
|
5426
6708
|
const api = createApiClient();
|
|
5427
6709
|
await api.storage.createEntityBranch({
|
|
@@ -5431,7 +6713,7 @@ function registerEntityBranchCommands(program) {
|
|
|
5431
6713
|
sourceEntityBranch: resolved.entityBranch,
|
|
5432
6714
|
targetEntityBranch: targetBranch
|
|
5433
6715
|
});
|
|
5434
|
-
console.log(
|
|
6716
|
+
console.log(chalk31.green(`Entity branch "${targetBranch}" created from "${resolved.entityBranch}".`));
|
|
5435
6717
|
} catch (error) {
|
|
5436
6718
|
handleError(error);
|
|
5437
6719
|
}
|
|
@@ -5439,7 +6721,7 @@ function registerEntityBranchCommands(program) {
|
|
|
5439
6721
|
}
|
|
5440
6722
|
|
|
5441
6723
|
// src/commands/subscription/index.ts
|
|
5442
|
-
function
|
|
6724
|
+
function getOutputFormat21(cmd) {
|
|
5443
6725
|
const config = loadConfig();
|
|
5444
6726
|
const globalOpts = cmd.optsWithGlobals();
|
|
5445
6727
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -5450,7 +6732,7 @@ function registerSubscriptionCommand(program) {
|
|
|
5450
6732
|
try {
|
|
5451
6733
|
const api = createApiClient();
|
|
5452
6734
|
const s = await api.admin.getCurrentSubscription();
|
|
5453
|
-
format(s, { format:
|
|
6735
|
+
format(s, { format: getOutputFormat21(cmd) });
|
|
5454
6736
|
} catch (error) {
|
|
5455
6737
|
handleError(error);
|
|
5456
6738
|
}
|
|
@@ -5459,7 +6741,7 @@ function registerSubscriptionCommand(program) {
|
|
|
5459
6741
|
try {
|
|
5460
6742
|
const api = createApiClient();
|
|
5461
6743
|
const s = await api.admin.getNextSubscription();
|
|
5462
|
-
format(s, { format:
|
|
6744
|
+
format(s, { format: getOutputFormat21(cmd) });
|
|
5463
6745
|
} catch (error) {
|
|
5464
6746
|
handleError(error);
|
|
5465
6747
|
}
|
|
@@ -5468,7 +6750,7 @@ function registerSubscriptionCommand(program) {
|
|
|
5468
6750
|
try {
|
|
5469
6751
|
const api = createApiClient();
|
|
5470
6752
|
const plans = await api.admin.getSubscriptionPlans(subscriptionToken);
|
|
5471
|
-
format(plans, { format:
|
|
6753
|
+
format(plans, { format: getOutputFormat21(cmd) });
|
|
5472
6754
|
} catch (error) {
|
|
5473
6755
|
handleError(error);
|
|
5474
6756
|
}
|
|
@@ -5476,9 +6758,9 @@ function registerSubscriptionCommand(program) {
|
|
|
5476
6758
|
}
|
|
5477
6759
|
|
|
5478
6760
|
// src/commands/invoice/index.ts
|
|
5479
|
-
import
|
|
5480
|
-
import * as
|
|
5481
|
-
function
|
|
6761
|
+
import chalk32 from "chalk";
|
|
6762
|
+
import * as fs10 from "fs";
|
|
6763
|
+
function getOutputFormat22(cmd) {
|
|
5482
6764
|
const config = loadConfig();
|
|
5483
6765
|
const globalOpts = cmd.optsWithGlobals();
|
|
5484
6766
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -5490,7 +6772,7 @@ function registerInvoiceCommand(program) {
|
|
|
5490
6772
|
const api = createApiClient();
|
|
5491
6773
|
const invoices = await api.admin.getInvoices();
|
|
5492
6774
|
format(invoices, {
|
|
5493
|
-
format:
|
|
6775
|
+
format: getOutputFormat22(cmd),
|
|
5494
6776
|
columns: ["invoiceNumber", "issued", "periodFrom", "periodTo", "total", "status"]
|
|
5495
6777
|
});
|
|
5496
6778
|
} catch (error) {
|
|
@@ -5503,8 +6785,8 @@ function registerInvoiceCommand(program) {
|
|
|
5503
6785
|
const response = await api.admin.downloadInvoice(invoiceNumber, fileName);
|
|
5504
6786
|
const buffer = Buffer.from(await response.arrayBuffer());
|
|
5505
6787
|
const outPath = options.out ?? fileName;
|
|
5506
|
-
|
|
5507
|
-
console.log(
|
|
6788
|
+
fs10.writeFileSync(outPath, buffer);
|
|
6789
|
+
console.log(chalk32.green(`Invoice saved to ${outPath}`));
|
|
5508
6790
|
} catch (error) {
|
|
5509
6791
|
handleError(error);
|
|
5510
6792
|
}
|
|
@@ -5512,10 +6794,10 @@ function registerInvoiceCommand(program) {
|
|
|
5512
6794
|
}
|
|
5513
6795
|
|
|
5514
6796
|
// src/commands/shell/index.ts
|
|
5515
|
-
import
|
|
5516
|
-
import * as
|
|
6797
|
+
import chalk33 from "chalk";
|
|
6798
|
+
import * as fs11 from "fs";
|
|
5517
6799
|
import * as os3 from "os";
|
|
5518
|
-
import * as
|
|
6800
|
+
import * as path8 from "path";
|
|
5519
6801
|
import { spawn as spawn3 } from "child_process";
|
|
5520
6802
|
import { randomUUID as randomUUID3 } from "crypto";
|
|
5521
6803
|
function extensionFor2(language) {
|
|
@@ -5528,16 +6810,16 @@ function extensionFor2(language) {
|
|
|
5528
6810
|
return "txt";
|
|
5529
6811
|
}
|
|
5530
6812
|
async function openInEditor(initial, ext) {
|
|
5531
|
-
const tmpFile =
|
|
5532
|
-
|
|
6813
|
+
const tmpFile = path8.join(os3.tmpdir(), `diafunc-shell-${randomUUID3()}.${ext}`);
|
|
6814
|
+
fs11.writeFileSync(tmpFile, initial);
|
|
5533
6815
|
const editor = process.env.VISUAL ?? process.env.EDITOR ?? "vi";
|
|
5534
6816
|
await new Promise((resolve, reject) => {
|
|
5535
6817
|
const child = spawn3(editor, [tmpFile], { stdio: "inherit" });
|
|
5536
6818
|
child.on("exit", (code) => code === 0 ? resolve() : reject(new Error(`Editor exited with ${code}`)));
|
|
5537
6819
|
child.on("error", reject);
|
|
5538
6820
|
});
|
|
5539
|
-
const content =
|
|
5540
|
-
|
|
6821
|
+
const content = fs11.readFileSync(tmpFile, "utf-8");
|
|
6822
|
+
fs11.unlinkSync(tmpFile);
|
|
5541
6823
|
return content;
|
|
5542
6824
|
}
|
|
5543
6825
|
function utcNowParts() {
|
|
@@ -5578,21 +6860,21 @@ async function evaluate(api, fnRef, language, sourceCode) {
|
|
|
5578
6860
|
}, false);
|
|
5579
6861
|
if (result.outputs?.length) {
|
|
5580
6862
|
for (const out of result.outputs) {
|
|
5581
|
-
console.log(
|
|
6863
|
+
console.log(chalk33.dim(` [${out.type}]`) + " " + out.output);
|
|
5582
6864
|
}
|
|
5583
6865
|
}
|
|
5584
6866
|
if (result.successful) {
|
|
5585
6867
|
if (result.result) {
|
|
5586
|
-
console.log(
|
|
6868
|
+
console.log(chalk33.green("=> ") + result.result);
|
|
5587
6869
|
} else {
|
|
5588
|
-
console.log(
|
|
6870
|
+
console.log(chalk33.dim("=> (no value)"));
|
|
5589
6871
|
}
|
|
5590
6872
|
const duration = result.completed - result.started;
|
|
5591
|
-
console.log(
|
|
6873
|
+
console.log(chalk33.dim(` [${duration}ms \xB7 ${evaluationId}]`));
|
|
5592
6874
|
} else {
|
|
5593
|
-
console.log(
|
|
6875
|
+
console.log(chalk33.red("error: ") + result.error);
|
|
5594
6876
|
if (result.lineNumber > 0) {
|
|
5595
|
-
console.log(
|
|
6877
|
+
console.log(chalk33.dim(` at line ${result.lineNumber}, col ${result.columnNumber}`));
|
|
5596
6878
|
}
|
|
5597
6879
|
}
|
|
5598
6880
|
}
|
|
@@ -5600,9 +6882,9 @@ function registerShellCommand(program) {
|
|
|
5600
6882
|
program.command("shell").description("Interactive REPL for function code evaluation").option("--function <ref>", "Function entity reference to use as scratch (required)").option("--language <lang>", "Source language", "JavaScript").action(async (options, cmd) => {
|
|
5601
6883
|
try {
|
|
5602
6884
|
if (!options.function) {
|
|
5603
|
-
console.error(
|
|
5604
|
-
console.error(
|
|
5605
|
-
console.error(
|
|
6885
|
+
console.error(chalk33.red("Missing --function <ref>."));
|
|
6886
|
+
console.error(chalk33.dim("Pass an existing or new function entity reference to use as the shell target."));
|
|
6887
|
+
console.error(chalk33.dim("Example: diafunc shell --function my-project/main/scratch/main --language JavaScript"));
|
|
5606
6888
|
process.exit(1);
|
|
5607
6889
|
}
|
|
5608
6890
|
const config = loadConfig();
|
|
@@ -5613,18 +6895,18 @@ function registerShellCommand(program) {
|
|
|
5613
6895
|
});
|
|
5614
6896
|
const api = createApiClient();
|
|
5615
6897
|
const { input: promptInput } = await import("@inquirer/prompts");
|
|
5616
|
-
const { getUpdateNotice } = await import("./update-check-
|
|
5617
|
-
console.log(
|
|
5618
|
-
console.log(
|
|
5619
|
-
console.log(
|
|
6898
|
+
const { getUpdateNotice } = await import("./update-check-KL3CHODI.js");
|
|
6899
|
+
console.log(chalk33.bold("Diafunc shell") + chalk33.dim(` \xB7 function ${fnRef.entityId} \xB7 ${options.language}`));
|
|
6900
|
+
console.log(chalk33.dim(`Endpoint: ${config.profiles[config.currentProfile]?.endpoint}`));
|
|
6901
|
+
console.log(chalk33.dim("Commands: /edit (multi-line in $EDITOR), /lang <name>, /file <path>, /help, /quit"));
|
|
5620
6902
|
const notice = await getUpdateNotice();
|
|
5621
|
-
if (notice) console.log(
|
|
6903
|
+
if (notice) console.log(chalk33.dim(notice));
|
|
5622
6904
|
console.log();
|
|
5623
6905
|
let language = options.language;
|
|
5624
6906
|
for (; ; ) {
|
|
5625
6907
|
let line;
|
|
5626
6908
|
try {
|
|
5627
|
-
line = await promptInput({ message:
|
|
6909
|
+
line = await promptInput({ message: chalk33.cyan.bold(`${language} >`) });
|
|
5628
6910
|
} catch {
|
|
5629
6911
|
console.log();
|
|
5630
6912
|
return;
|
|
@@ -5642,54 +6924,54 @@ function registerShellCommand(program) {
|
|
|
5642
6924
|
case "help":
|
|
5643
6925
|
case "h":
|
|
5644
6926
|
case "?":
|
|
5645
|
-
console.log(
|
|
5646
|
-
console.log(
|
|
5647
|
-
console.log(
|
|
5648
|
-
console.log(
|
|
6927
|
+
console.log(chalk33.dim(" /edit open $EDITOR for multi-line code"));
|
|
6928
|
+
console.log(chalk33.dim(" /file <path> evaluate the contents of a file"));
|
|
6929
|
+
console.log(chalk33.dim(" /lang <name> switch language (Java, JavaScript, Kotlin, Python, Scala)"));
|
|
6930
|
+
console.log(chalk33.dim(" /quit exit the shell"));
|
|
5649
6931
|
continue;
|
|
5650
6932
|
case "lang":
|
|
5651
6933
|
if (arg) language = arg;
|
|
5652
|
-
console.log(
|
|
6934
|
+
console.log(chalk33.dim(`Language: ${language}`));
|
|
5653
6935
|
continue;
|
|
5654
6936
|
case "edit": {
|
|
5655
6937
|
const sourceCode = await openInEditor("", extensionFor2(language));
|
|
5656
6938
|
if (!sourceCode.trim()) {
|
|
5657
|
-
console.log(
|
|
6939
|
+
console.log(chalk33.dim("(empty \u2014 not evaluated)"));
|
|
5658
6940
|
continue;
|
|
5659
6941
|
}
|
|
5660
6942
|
try {
|
|
5661
6943
|
await evaluate(api, fnRef, language, sourceCode);
|
|
5662
6944
|
} catch (e) {
|
|
5663
|
-
console.error(
|
|
6945
|
+
console.error(chalk33.red(e.message));
|
|
5664
6946
|
}
|
|
5665
6947
|
continue;
|
|
5666
6948
|
}
|
|
5667
6949
|
case "file": {
|
|
5668
6950
|
if (!arg) {
|
|
5669
|
-
console.log(
|
|
6951
|
+
console.log(chalk33.dim("usage: /file <path>"));
|
|
5670
6952
|
continue;
|
|
5671
6953
|
}
|
|
5672
|
-
if (!
|
|
5673
|
-
console.log(
|
|
6954
|
+
if (!fs11.existsSync(arg)) {
|
|
6955
|
+
console.log(chalk33.red(`file not found: ${arg}`));
|
|
5674
6956
|
continue;
|
|
5675
6957
|
}
|
|
5676
|
-
const sourceCode =
|
|
6958
|
+
const sourceCode = fs11.readFileSync(arg, "utf-8");
|
|
5677
6959
|
try {
|
|
5678
6960
|
await evaluate(api, fnRef, language, sourceCode);
|
|
5679
6961
|
} catch (e) {
|
|
5680
|
-
console.error(
|
|
6962
|
+
console.error(chalk33.red(e.message));
|
|
5681
6963
|
}
|
|
5682
6964
|
continue;
|
|
5683
6965
|
}
|
|
5684
6966
|
default:
|
|
5685
|
-
console.log(
|
|
6967
|
+
console.log(chalk33.dim(`Unknown command: /${cmd2}. Try /help.`));
|
|
5686
6968
|
continue;
|
|
5687
6969
|
}
|
|
5688
6970
|
}
|
|
5689
6971
|
try {
|
|
5690
6972
|
await evaluate(api, fnRef, language, trimmed);
|
|
5691
6973
|
} catch (e) {
|
|
5692
|
-
console.error(
|
|
6974
|
+
console.error(chalk33.red(e.message));
|
|
5693
6975
|
}
|
|
5694
6976
|
}
|
|
5695
6977
|
} catch (error) {
|
|
@@ -5699,19 +6981,19 @@ function registerShellCommand(program) {
|
|
|
5699
6981
|
}
|
|
5700
6982
|
|
|
5701
6983
|
// src/commands/update/index.ts
|
|
5702
|
-
import
|
|
5703
|
-
import * as
|
|
6984
|
+
import chalk34 from "chalk";
|
|
6985
|
+
import * as path9 from "path";
|
|
5704
6986
|
import { spawn as spawn4 } from "child_process";
|
|
5705
6987
|
|
|
5706
6988
|
// src/util/install-method.ts
|
|
5707
|
-
import * as
|
|
6989
|
+
import * as fs12 from "fs";
|
|
5708
6990
|
function detectInstall() {
|
|
5709
6991
|
const exec = process.execPath;
|
|
5710
6992
|
const exe = exec.replace(/\\/g, "/").toLowerCase();
|
|
5711
6993
|
const isNode = exe.endsWith("/node") || exe.endsWith("/node.exe");
|
|
5712
6994
|
return {
|
|
5713
6995
|
method: isNode ? "npm" : "binary",
|
|
5714
|
-
binaryPath: isNode ? exec :
|
|
6996
|
+
binaryPath: isNode ? exec : fs12.realpathSync(exec)
|
|
5715
6997
|
};
|
|
5716
6998
|
}
|
|
5717
6999
|
|
|
@@ -5745,17 +7027,17 @@ function registerUpdateCommand(program) {
|
|
|
5745
7027
|
const install = detectInstall();
|
|
5746
7028
|
const latest = await fetchLatestVersion();
|
|
5747
7029
|
if (latest === package_default.version) {
|
|
5748
|
-
console.log(
|
|
7030
|
+
console.log(chalk34.dim(`diafunc is already at the latest version (${package_default.version}).`));
|
|
5749
7031
|
return;
|
|
5750
7032
|
}
|
|
5751
|
-
console.log(
|
|
7033
|
+
console.log(chalk34.dim(`Current: ${package_default.version} \u2192 Available: ${latest}`));
|
|
5752
7034
|
if (install.method === "npm") {
|
|
5753
7035
|
console.log();
|
|
5754
7036
|
console.log("Installed via npm. Upgrade with:");
|
|
5755
|
-
console.log(
|
|
7037
|
+
console.log(chalk34.bold(` npm install -g @diafunc/cli@${latest}`));
|
|
5756
7038
|
return;
|
|
5757
7039
|
}
|
|
5758
|
-
const installDir =
|
|
7040
|
+
const installDir = path9.dirname(install.binaryPath);
|
|
5759
7041
|
console.log(`Installing diafunc ${latest} to ${installDir}...`);
|
|
5760
7042
|
console.log();
|
|
5761
7043
|
await runInstaller(installDir);
|
|
@@ -5766,23 +7048,23 @@ function registerUpdateCommand(program) {
|
|
|
5766
7048
|
}
|
|
5767
7049
|
|
|
5768
7050
|
// src/commands/uninstall/index.ts
|
|
5769
|
-
import
|
|
7051
|
+
import chalk35 from "chalk";
|
|
5770
7052
|
import { spawn as spawn5 } from "child_process";
|
|
5771
|
-
import * as
|
|
7053
|
+
import * as fs13 from "fs";
|
|
5772
7054
|
import * as os4 from "os";
|
|
5773
|
-
import * as
|
|
7055
|
+
import * as path10 from "path";
|
|
5774
7056
|
function registerUninstallCommand(program) {
|
|
5775
7057
|
program.command("uninstall").description("Remove the CLI binary and (optionally) its config from this machine").option("-y, --yes", "Skip confirmation prompts").option("--purge", "Also remove ~/.diafunc/ (config + credentials) without prompting").action(async (options) => {
|
|
5776
7058
|
try {
|
|
5777
7059
|
const install = detectInstall();
|
|
5778
|
-
const configDir =
|
|
7060
|
+
const configDir = path10.join(os4.homedir(), ".diafunc");
|
|
5779
7061
|
if (install.method === "npm") {
|
|
5780
7062
|
console.log("Installed via npm. Remove with:");
|
|
5781
|
-
console.log(
|
|
5782
|
-
if (
|
|
7063
|
+
console.log(chalk35.bold(" npm uninstall -g @diafunc/cli"));
|
|
7064
|
+
if (fs13.existsSync(configDir)) {
|
|
5783
7065
|
console.log();
|
|
5784
7066
|
console.log(`Config + credentials live at ${configDir} \u2014 remove manually with:`);
|
|
5785
|
-
console.log(
|
|
7067
|
+
console.log(chalk35.bold(` rm -rf ${configDir}`));
|
|
5786
7068
|
}
|
|
5787
7069
|
return;
|
|
5788
7070
|
}
|
|
@@ -5792,19 +7074,19 @@ function registerUninstallCommand(program) {
|
|
|
5792
7074
|
default: false
|
|
5793
7075
|
});
|
|
5794
7076
|
if (!removeBinary) {
|
|
5795
|
-
console.log(
|
|
7077
|
+
console.log(chalk35.dim("Aborted."));
|
|
5796
7078
|
return;
|
|
5797
7079
|
}
|
|
5798
7080
|
let removeConfig = options.purge ?? false;
|
|
5799
|
-
if (!options.purge && !options.yes &&
|
|
7081
|
+
if (!options.purge && !options.yes && fs13.existsSync(configDir)) {
|
|
5800
7082
|
removeConfig = await confirm({
|
|
5801
7083
|
message: `Also remove ${configDir} (config + credentials)?`,
|
|
5802
7084
|
default: false
|
|
5803
7085
|
});
|
|
5804
7086
|
}
|
|
5805
|
-
if (removeConfig &&
|
|
5806
|
-
|
|
5807
|
-
console.log(
|
|
7087
|
+
if (removeConfig && fs13.existsSync(configDir)) {
|
|
7088
|
+
fs13.rmSync(configDir, { recursive: true, force: true });
|
|
7089
|
+
console.log(chalk35.dim(`Removed ${configDir}`));
|
|
5808
7090
|
}
|
|
5809
7091
|
if (process.platform === "win32") {
|
|
5810
7092
|
const cmd = `timeout /t 2 /nobreak >nul & del /f /q "${install.binaryPath}"`;
|
|
@@ -5814,13 +7096,13 @@ function registerUninstallCommand(program) {
|
|
|
5814
7096
|
windowsHide: true
|
|
5815
7097
|
});
|
|
5816
7098
|
child.unref();
|
|
5817
|
-
console.log(
|
|
7099
|
+
console.log(chalk35.dim(`Removing ${install.binaryPath} on exit...`));
|
|
5818
7100
|
console.log();
|
|
5819
7101
|
console.log("diafunc uninstalled.");
|
|
5820
7102
|
return;
|
|
5821
7103
|
}
|
|
5822
|
-
|
|
5823
|
-
console.log(
|
|
7104
|
+
fs13.rmSync(install.binaryPath, { force: true });
|
|
7105
|
+
console.log(chalk35.dim(`Removed ${install.binaryPath}`));
|
|
5824
7106
|
console.log();
|
|
5825
7107
|
console.log("diafunc uninstalled.");
|
|
5826
7108
|
} catch (error) {
|
|
@@ -5846,6 +7128,7 @@ function createProgram() {
|
|
|
5846
7128
|
registerEventCommands(program);
|
|
5847
7129
|
registerBranchCommands(program);
|
|
5848
7130
|
registerTableCommands(program);
|
|
7131
|
+
registerNotebookCommands(program);
|
|
5849
7132
|
registerFunctionCommands(program);
|
|
5850
7133
|
registerTriggerCommands(program);
|
|
5851
7134
|
registerScheduleCommands(program);
|
|
@@ -5855,6 +7138,9 @@ function createProgram() {
|
|
|
5855
7138
|
registerAdminCommands(program);
|
|
5856
7139
|
registerStatusCommands(program);
|
|
5857
7140
|
registerAnalyzeCommand(program);
|
|
7141
|
+
registerDataSourcesCommands(program);
|
|
7142
|
+
registerTableExportersCommands(program);
|
|
7143
|
+
registerSkeletonCommands(program);
|
|
5858
7144
|
registerCompletionCommand(program);
|
|
5859
7145
|
registerWhoamiCommand(program);
|
|
5860
7146
|
registerUtilizationCommand(program);
|
|
@@ -5870,4 +7156,4 @@ function createProgram() {
|
|
|
5870
7156
|
export {
|
|
5871
7157
|
createProgram
|
|
5872
7158
|
};
|
|
5873
|
-
//# sourceMappingURL=chunk-
|
|
7159
|
+
//# sourceMappingURL=chunk-E4O67FMQ.js.map
|