@diafunc/cli 0.7.0 → 0.8.1
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-QAMANXTQ.js → chunk-GIWRWVU6.js} +2 -2
- package/dist/{chunk-QAMANXTQ.js.map → chunk-GIWRWVU6.js.map} +1 -1
- package/dist/{chunk-3AY25U63.js → chunk-SCDOFUA4.js} +2 -2
- package/dist/{chunk-L63Y72FJ.js → chunk-WHWVHDRF.js} +1714 -597
- package/dist/chunk-WHWVHDRF.js.map +1 -0
- package/dist/src/index.js +2 -2
- package/dist/update-check-2X2AIL52.js +8 -0
- package/package.json +1 -1
- package/dist/chunk-L63Y72FJ.js.map +0 -1
- package/dist/update-check-E3YHFRKF.js +0 -8
- /package/dist/{chunk-3AY25U63.js.map → chunk-SCDOFUA4.js.map} +0 -0
- /package/dist/{update-check-E3YHFRKF.js.map → update-check-2X2AIL52.js.map} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
package_default
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-GIWRWVU6.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({
|
|
@@ -1190,6 +1172,20 @@ function enc(s) {
|
|
|
1190
1172
|
function entityPath(ref) {
|
|
1191
1173
|
return `/${enc(ref.projectId)}/${enc(ref.projectBranch)}/${enc(ref.entityId)}/${enc(ref.entityBranch)}`;
|
|
1192
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
|
+
}
|
|
1193
1189
|
function createStorageService(client) {
|
|
1194
1190
|
return {
|
|
1195
1191
|
// --- Entities ---
|
|
@@ -1331,14 +1327,14 @@ function createStorageService(client) {
|
|
|
1331
1327
|
});
|
|
1332
1328
|
},
|
|
1333
1329
|
async deleteLink(projectId, projectBranch, sourceEntityId, sourceEntityBranch, linkId, targetEntityId, targetEntityBranch) {
|
|
1334
|
-
let
|
|
1330
|
+
let path11 = `/links/actual/${enc(projectId)}/${enc(projectBranch)}/${enc(sourceEntityId)}/${enc(sourceEntityBranch)}/${enc(linkId)}`;
|
|
1335
1331
|
if (targetEntityId && targetEntityBranch) {
|
|
1336
|
-
|
|
1332
|
+
path11 += `/${enc(targetEntityId)}/${enc(targetEntityBranch)}`;
|
|
1337
1333
|
}
|
|
1338
1334
|
return client.request({
|
|
1339
1335
|
method: "DELETE",
|
|
1340
1336
|
service: SERVICE3,
|
|
1341
|
-
path:
|
|
1337
|
+
path: path11
|
|
1342
1338
|
});
|
|
1343
1339
|
},
|
|
1344
1340
|
// --- Events ---
|
|
@@ -1395,13 +1391,27 @@ function createStorageService(client) {
|
|
|
1395
1391
|
path: `/tables${entityPath(ref)}/rows`
|
|
1396
1392
|
});
|
|
1397
1393
|
},
|
|
1398
|
-
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) {
|
|
1399
1402
|
return client.request({
|
|
1400
1403
|
method: "DELETE",
|
|
1401
1404
|
service: SERVICE3,
|
|
1402
1405
|
path: `/tables${entityPath(ref)}/rows/${rowIndex}`
|
|
1403
1406
|
});
|
|
1404
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
|
+
},
|
|
1405
1415
|
async appendColumn(ref) {
|
|
1406
1416
|
return client.request({
|
|
1407
1417
|
method: "POST",
|
|
@@ -1409,13 +1419,27 @@ function createStorageService(client) {
|
|
|
1409
1419
|
path: `/tables${entityPath(ref)}/columns`
|
|
1410
1420
|
});
|
|
1411
1421
|
},
|
|
1412
|
-
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) {
|
|
1413
1430
|
return client.request({
|
|
1414
1431
|
method: "DELETE",
|
|
1415
1432
|
service: SERVICE3,
|
|
1416
1433
|
path: `/tables${entityPath(ref)}/columns/${columnIndex}`
|
|
1417
1434
|
});
|
|
1418
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
|
+
},
|
|
1419
1443
|
async mergeCells(ref, cells) {
|
|
1420
1444
|
return client.request({
|
|
1421
1445
|
method: "PUT",
|
|
@@ -1424,7 +1448,7 @@ function createStorageService(client) {
|
|
|
1424
1448
|
body: cells
|
|
1425
1449
|
});
|
|
1426
1450
|
},
|
|
1427
|
-
async
|
|
1451
|
+
async removeCell(ref, rowIndex, columnIndex) {
|
|
1428
1452
|
return client.request({
|
|
1429
1453
|
method: "DELETE",
|
|
1430
1454
|
service: SERVICE3,
|
|
@@ -1439,15 +1463,24 @@ function createStorageService(client) {
|
|
|
1439
1463
|
});
|
|
1440
1464
|
},
|
|
1441
1465
|
// --- Table Import/Export ---
|
|
1442
|
-
async importTable(ref, formData,
|
|
1466
|
+
async importTable(ref, formData, selection) {
|
|
1467
|
+
const query = {};
|
|
1468
|
+
if (selection) query.selection = selection;
|
|
1443
1469
|
return client.request({
|
|
1444
1470
|
method: "PUT",
|
|
1445
1471
|
service: SERVICE3,
|
|
1446
1472
|
path: `/table-imports${entityPath(ref)}`,
|
|
1447
|
-
query:
|
|
1473
|
+
query: Object.keys(query).length > 0 ? query : void 0,
|
|
1448
1474
|
rawBody: formData
|
|
1449
1475
|
});
|
|
1450
1476
|
},
|
|
1477
|
+
async getSupportedImportFormats() {
|
|
1478
|
+
return client.request({
|
|
1479
|
+
method: "GET",
|
|
1480
|
+
service: SERVICE3,
|
|
1481
|
+
path: `/table-imports/supported-formats`
|
|
1482
|
+
});
|
|
1483
|
+
},
|
|
1451
1484
|
async getImport(ref, importId) {
|
|
1452
1485
|
return client.request({
|
|
1453
1486
|
method: "GET",
|
|
@@ -1455,18 +1488,68 @@ function createStorageService(client) {
|
|
|
1455
1488
|
path: `/imports${entityPath(ref)}/${enc(importId)}`
|
|
1456
1489
|
});
|
|
1457
1490
|
},
|
|
1458
|
-
|
|
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);
|
|
1459
1514
|
return client.requestRaw({
|
|
1460
1515
|
method: "POST",
|
|
1461
1516
|
service: SERVICE3,
|
|
1462
|
-
path: `/table-exports${entityPath(ref)}/
|
|
1517
|
+
path: `/table-exports${entityPath(ref)}/${enc(format2)}/stream`,
|
|
1518
|
+
query: Object.keys(query).length > 0 ? query : void 0
|
|
1463
1519
|
});
|
|
1464
1520
|
},
|
|
1521
|
+
async exportTableCsv(ref) {
|
|
1522
|
+
return this.exportTable(ref, "csv");
|
|
1523
|
+
},
|
|
1465
1524
|
async exportTableExcel(ref) {
|
|
1525
|
+
return this.exportTable(ref, "excel");
|
|
1526
|
+
},
|
|
1527
|
+
async getSupportedExportFormats() {
|
|
1528
|
+
return client.request({
|
|
1529
|
+
method: "GET",
|
|
1530
|
+
service: SERVICE3,
|
|
1531
|
+
path: `/table-exports/supported-formats`
|
|
1532
|
+
});
|
|
1533
|
+
},
|
|
1534
|
+
/** List all async exports for an entity (see ExportsResource#getExports). */
|
|
1535
|
+
async listExports(ref) {
|
|
1536
|
+
return client.request({
|
|
1537
|
+
method: "GET",
|
|
1538
|
+
service: SERVICE3,
|
|
1539
|
+
path: `/exports${entityPath(ref)}`
|
|
1540
|
+
});
|
|
1541
|
+
},
|
|
1542
|
+
/**
|
|
1543
|
+
* Download the bytes of a completed async export.
|
|
1544
|
+
* Path mirrors ExportsResource#getContent: /exports/{entity}/{exportId}/{filename}.
|
|
1545
|
+
* The {filename} segment is part of the server URL but is not used for lookup —
|
|
1546
|
+
* only exportId determines the row; pass StorageExport.filename verbatim.
|
|
1547
|
+
*/
|
|
1548
|
+
async downloadExport(ref, exportId, filename) {
|
|
1466
1549
|
return client.requestRaw({
|
|
1467
|
-
method: "
|
|
1550
|
+
method: "GET",
|
|
1468
1551
|
service: SERVICE3,
|
|
1469
|
-
path: `/
|
|
1552
|
+
path: `/exports${entityPath(ref)}/${enc(exportId)}/${enc(filename)}`
|
|
1470
1553
|
});
|
|
1471
1554
|
},
|
|
1472
1555
|
// --- Branches ---
|
|
@@ -1580,6 +1663,29 @@ function createStorageService(client) {
|
|
|
1580
1663
|
},
|
|
1581
1664
|
// --- Event write ops (moved from read-only block) ---
|
|
1582
1665
|
// NOTE: createEvents / consumeEvents already exist above in the Events section.
|
|
1666
|
+
// --- User-defined exporters (UDE) ---
|
|
1667
|
+
async listUserDefinedExporters() {
|
|
1668
|
+
return client.request({
|
|
1669
|
+
method: "GET",
|
|
1670
|
+
service: SERVICE3,
|
|
1671
|
+
path: `/table-exporters`
|
|
1672
|
+
});
|
|
1673
|
+
},
|
|
1674
|
+
async registerUserDefinedExporter(request) {
|
|
1675
|
+
return client.request({
|
|
1676
|
+
method: "POST",
|
|
1677
|
+
service: SERVICE3,
|
|
1678
|
+
path: `/table-exporters`,
|
|
1679
|
+
body: request
|
|
1680
|
+
});
|
|
1681
|
+
},
|
|
1682
|
+
async deleteUserDefinedExporter(id) {
|
|
1683
|
+
await client.request({
|
|
1684
|
+
method: "DELETE",
|
|
1685
|
+
service: SERVICE3,
|
|
1686
|
+
path: `/table-exporters/${enc(id)}`
|
|
1687
|
+
});
|
|
1688
|
+
},
|
|
1583
1689
|
// --- Data sources ---
|
|
1584
1690
|
async createDataSource(request) {
|
|
1585
1691
|
return client.request({
|
|
@@ -1597,6 +1703,14 @@ function createStorageService(client) {
|
|
|
1597
1703
|
query: projectId ? { projectId } : void 0
|
|
1598
1704
|
});
|
|
1599
1705
|
},
|
|
1706
|
+
async getDataSourceDashboard(projectId) {
|
|
1707
|
+
return client.request({
|
|
1708
|
+
method: "GET",
|
|
1709
|
+
service: SERVICE3,
|
|
1710
|
+
path: `/data-sources/dashboard`,
|
|
1711
|
+
query: { projectId }
|
|
1712
|
+
});
|
|
1713
|
+
},
|
|
1600
1714
|
async getDataSource(id) {
|
|
1601
1715
|
return client.request({
|
|
1602
1716
|
method: "GET",
|
|
@@ -1647,6 +1761,131 @@ function createStorageService(client) {
|
|
|
1647
1761
|
service: SERVICE3,
|
|
1648
1762
|
path: `/data-sources/types`
|
|
1649
1763
|
});
|
|
1764
|
+
},
|
|
1765
|
+
// --- Skeletons ---
|
|
1766
|
+
async createSkeleton(request) {
|
|
1767
|
+
return client.request({
|
|
1768
|
+
method: "POST",
|
|
1769
|
+
service: SERVICE3,
|
|
1770
|
+
path: `/skeletons`,
|
|
1771
|
+
body: request
|
|
1772
|
+
});
|
|
1773
|
+
},
|
|
1774
|
+
async listSkeletons(projectId) {
|
|
1775
|
+
return client.request({
|
|
1776
|
+
method: "GET",
|
|
1777
|
+
service: SERVICE3,
|
|
1778
|
+
path: `/skeletons`,
|
|
1779
|
+
query: { projectId }
|
|
1780
|
+
});
|
|
1781
|
+
},
|
|
1782
|
+
async getSkeleton(id) {
|
|
1783
|
+
return client.request({
|
|
1784
|
+
method: "GET",
|
|
1785
|
+
service: SERVICE3,
|
|
1786
|
+
path: `/skeletons/${enc(id)}`
|
|
1787
|
+
});
|
|
1788
|
+
},
|
|
1789
|
+
async updateSkeleton(id, request) {
|
|
1790
|
+
return client.request({
|
|
1791
|
+
method: "PUT",
|
|
1792
|
+
service: SERVICE3,
|
|
1793
|
+
path: `/skeletons/${enc(id)}`,
|
|
1794
|
+
body: request
|
|
1795
|
+
});
|
|
1796
|
+
},
|
|
1797
|
+
async deleteSkeleton(id) {
|
|
1798
|
+
await client.request({
|
|
1799
|
+
method: "DELETE",
|
|
1800
|
+
service: SERVICE3,
|
|
1801
|
+
path: `/skeletons/${enc(id)}`
|
|
1802
|
+
});
|
|
1803
|
+
},
|
|
1804
|
+
// --- Notebook bundles ---
|
|
1805
|
+
/** Queue an async bundle export; returns the bundleId for polling. */
|
|
1806
|
+
async exportBundle(projectId, projectBranch, request) {
|
|
1807
|
+
return client.request({
|
|
1808
|
+
method: "POST",
|
|
1809
|
+
service: SERVICE3,
|
|
1810
|
+
path: `/notebook-bundles/${enc(projectId)}/${enc(projectBranch)}/export`,
|
|
1811
|
+
body: request
|
|
1812
|
+
});
|
|
1813
|
+
},
|
|
1814
|
+
/** Streaming download via the synchronous /stream endpoint; pipe bytes to disk. */
|
|
1815
|
+
async streamBundle(projectId, projectBranch, request) {
|
|
1816
|
+
return client.requestRaw({
|
|
1817
|
+
method: "POST",
|
|
1818
|
+
service: SERVICE3,
|
|
1819
|
+
path: `/notebook-bundles/${enc(projectId)}/${enc(projectBranch)}/export/stream`,
|
|
1820
|
+
body: request
|
|
1821
|
+
});
|
|
1822
|
+
},
|
|
1823
|
+
/** Queue an async whole-project (.dfproj) export (async-only; poll + download the result). */
|
|
1824
|
+
async exportProjectBundle(projectId, projectBranch) {
|
|
1825
|
+
return client.request({
|
|
1826
|
+
method: "POST",
|
|
1827
|
+
service: SERVICE3,
|
|
1828
|
+
path: `/project-bundles/${enc(projectId)}/${enc(projectBranch)}/export`
|
|
1829
|
+
});
|
|
1830
|
+
},
|
|
1831
|
+
/** Queue an async entity-subset (.dfset) export; returns the bundleId for polling. */
|
|
1832
|
+
async exportEntitySubset(projectId, projectBranch, request) {
|
|
1833
|
+
return client.request({
|
|
1834
|
+
method: "POST",
|
|
1835
|
+
service: SERVICE3,
|
|
1836
|
+
path: `/entity-subset-bundles/${enc(projectId)}/${enc(projectBranch)}/export`,
|
|
1837
|
+
body: request
|
|
1838
|
+
});
|
|
1839
|
+
},
|
|
1840
|
+
/** Streaming download of an entity-subset bundle via the synchronous /stream endpoint. */
|
|
1841
|
+
async streamEntitySubset(projectId, projectBranch, request) {
|
|
1842
|
+
return client.requestRaw({
|
|
1843
|
+
method: "POST",
|
|
1844
|
+
service: SERVICE3,
|
|
1845
|
+
path: `/entity-subset-bundles/${enc(projectId)}/${enc(projectBranch)}/export/stream`,
|
|
1846
|
+
body: request
|
|
1847
|
+
});
|
|
1848
|
+
},
|
|
1849
|
+
async getBundles(projectId, projectBranch) {
|
|
1850
|
+
return client.request({
|
|
1851
|
+
method: "GET",
|
|
1852
|
+
service: SERVICE3,
|
|
1853
|
+
path: `/bundles/${enc(projectId)}/${enc(projectBranch)}`
|
|
1854
|
+
});
|
|
1855
|
+
},
|
|
1856
|
+
/** Download a finished bundle's bytes. */
|
|
1857
|
+
async getBundleContent(projectId, projectBranch, bundleId, filename) {
|
|
1858
|
+
return client.requestRaw({
|
|
1859
|
+
method: "GET",
|
|
1860
|
+
service: SERVICE3,
|
|
1861
|
+
path: `/bundles/${enc(projectId)}/${enc(projectBranch)}/${enc(bundleId)}/${enc(filename)}`
|
|
1862
|
+
});
|
|
1863
|
+
},
|
|
1864
|
+
async stopBundle(projectId, projectBranch, bundleId, filename) {
|
|
1865
|
+
await client.request({
|
|
1866
|
+
method: "DELETE",
|
|
1867
|
+
service: SERVICE3,
|
|
1868
|
+
path: `/bundles/${enc(projectId)}/${enc(projectBranch)}/${enc(bundleId)}/${enc(filename)}`
|
|
1869
|
+
});
|
|
1870
|
+
},
|
|
1871
|
+
/** Non-committing inventory of an uploaded bundle. */
|
|
1872
|
+
async previewBundleImport(projectId, projectBranch, formData) {
|
|
1873
|
+
return client.request({
|
|
1874
|
+
method: "POST",
|
|
1875
|
+
service: SERVICE3,
|
|
1876
|
+
path: `/notebook-bundle-imports/${enc(projectId)}/${enc(projectBranch)}/preview`,
|
|
1877
|
+
rawBody: formData
|
|
1878
|
+
});
|
|
1879
|
+
},
|
|
1880
|
+
/** Commit an uploaded bundle into the target project. */
|
|
1881
|
+
async importBundle(projectId, projectBranch, formData, onConflict = "copy") {
|
|
1882
|
+
return client.request({
|
|
1883
|
+
method: "POST",
|
|
1884
|
+
service: SERVICE3,
|
|
1885
|
+
path: `/notebook-bundle-imports/${enc(projectId)}/${enc(projectBranch)}/import`,
|
|
1886
|
+
query: { onConflict },
|
|
1887
|
+
rawBody: formData
|
|
1888
|
+
});
|
|
1650
1889
|
}
|
|
1651
1890
|
};
|
|
1652
1891
|
}
|
|
@@ -2095,8 +2334,8 @@ function registerConfigCommands(program) {
|
|
|
2095
2334
|
console.log(chalk7.green(`Profile "${name}" removed.`));
|
|
2096
2335
|
});
|
|
2097
2336
|
}
|
|
2098
|
-
function setNestedValue(obj,
|
|
2099
|
-
const keys =
|
|
2337
|
+
function setNestedValue(obj, path11, value) {
|
|
2338
|
+
const keys = path11.split(".");
|
|
2100
2339
|
let current = obj;
|
|
2101
2340
|
for (let i = 0; i < keys.length - 1; i++) {
|
|
2102
2341
|
const key = keys[i];
|
|
@@ -2107,8 +2346,8 @@ function setNestedValue(obj, path9, value) {
|
|
|
2107
2346
|
}
|
|
2108
2347
|
current[keys[keys.length - 1]] = value;
|
|
2109
2348
|
}
|
|
2110
|
-
function getNestedValue(obj,
|
|
2111
|
-
const keys =
|
|
2349
|
+
function getNestedValue(obj, path11) {
|
|
2350
|
+
const keys = path11.split(".");
|
|
2112
2351
|
let current = obj;
|
|
2113
2352
|
for (const key of keys) {
|
|
2114
2353
|
if (current === null || current === void 0 || typeof current !== "object") {
|
|
@@ -2120,59 +2359,243 @@ function getNestedValue(obj, path9) {
|
|
|
2120
2359
|
}
|
|
2121
2360
|
|
|
2122
2361
|
// src/commands/project/index.ts
|
|
2123
|
-
import
|
|
2124
|
-
|
|
2362
|
+
import chalk9 from "chalk";
|
|
2363
|
+
|
|
2364
|
+
// src/util/references.ts
|
|
2365
|
+
function parseEntityReference(ref, overrides) {
|
|
2125
2366
|
const config = loadConfig();
|
|
2126
|
-
const
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
try {
|
|
2133
|
-
const outputFormat = getOutputFormat(cmd);
|
|
2134
|
-
const api = createApiClient();
|
|
2135
|
-
const projects = options.all ? await api.admin.getAllProjects() : await api.admin.getProjects();
|
|
2136
|
-
format(projects, {
|
|
2137
|
-
format: outputFormat,
|
|
2138
|
-
columns: ["projectId", "groupId", "visibility", "language", "active", "locked"]
|
|
2139
|
-
});
|
|
2140
|
-
} catch (error) {
|
|
2141
|
-
handleError(error);
|
|
2367
|
+
const defaultProject = overrides?.project ?? config.defaults.project;
|
|
2368
|
+
const defaultBranch = overrides?.branch ?? config.defaults.branch ?? "main";
|
|
2369
|
+
if (!ref.includes("/") && ref.includes(":")) {
|
|
2370
|
+
const [entityId, entityBranch] = ref.split(":");
|
|
2371
|
+
if (!defaultProject) {
|
|
2372
|
+
throw new Error("No default project configured. Set one with: diafunc config set defaults.project <id>");
|
|
2142
2373
|
}
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2374
|
+
return {
|
|
2375
|
+
projectId: defaultProject,
|
|
2376
|
+
projectBranch: defaultBranch,
|
|
2377
|
+
entityId,
|
|
2378
|
+
entityBranch: entityBranch || defaultBranch
|
|
2379
|
+
};
|
|
2380
|
+
}
|
|
2381
|
+
const parts = ref.split("/");
|
|
2382
|
+
if (parts.length === 1) {
|
|
2383
|
+
if (!defaultProject) {
|
|
2384
|
+
throw new Error("No default project configured. Set one with: diafunc config set defaults.project <id>");
|
|
2152
2385
|
}
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2386
|
+
return {
|
|
2387
|
+
projectId: defaultProject,
|
|
2388
|
+
projectBranch: defaultBranch,
|
|
2389
|
+
entityId: parts[0],
|
|
2390
|
+
entityBranch: defaultBranch
|
|
2391
|
+
};
|
|
2392
|
+
}
|
|
2393
|
+
if (parts.length === 2) {
|
|
2394
|
+
return {
|
|
2395
|
+
projectId: parts[0],
|
|
2396
|
+
projectBranch: defaultBranch,
|
|
2397
|
+
entityId: parts[1],
|
|
2398
|
+
entityBranch: defaultBranch
|
|
2399
|
+
};
|
|
2400
|
+
}
|
|
2401
|
+
if (parts.length === 3) {
|
|
2402
|
+
if (parts[1] === "") {
|
|
2403
|
+
return {
|
|
2404
|
+
projectId: parts[0],
|
|
2405
|
+
projectBranch: defaultBranch,
|
|
2406
|
+
entityId: parts[2],
|
|
2407
|
+
entityBranch: defaultBranch
|
|
2408
|
+
};
|
|
2173
2409
|
}
|
|
2174
|
-
|
|
2175
|
-
|
|
2410
|
+
return {
|
|
2411
|
+
projectId: parts[0],
|
|
2412
|
+
projectBranch: parts[1],
|
|
2413
|
+
entityId: parts[2],
|
|
2414
|
+
entityBranch: defaultBranch
|
|
2415
|
+
};
|
|
2416
|
+
}
|
|
2417
|
+
if (parts.length === 4) {
|
|
2418
|
+
return {
|
|
2419
|
+
projectId: parts[0],
|
|
2420
|
+
projectBranch: parts[1] || defaultBranch,
|
|
2421
|
+
entityId: parts[2],
|
|
2422
|
+
entityBranch: parts[3] || defaultBranch
|
|
2423
|
+
};
|
|
2424
|
+
}
|
|
2425
|
+
throw new Error(
|
|
2426
|
+
`Invalid entity reference: "${ref}". Expected format: entityId, entityId:branch, or projectId/projectBranch/entityId/entityBranch`
|
|
2427
|
+
);
|
|
2428
|
+
}
|
|
2429
|
+
function parseProjectReference(ref, overrides) {
|
|
2430
|
+
const config = loadConfig();
|
|
2431
|
+
const defaultProject = overrides?.project ?? config.defaults.project;
|
|
2432
|
+
const defaultBranch = overrides?.branch ?? config.defaults.branch ?? "main";
|
|
2433
|
+
if (!ref.includes("/")) {
|
|
2434
|
+
return {
|
|
2435
|
+
projectId: ref || defaultProject,
|
|
2436
|
+
projectBranch: defaultBranch
|
|
2437
|
+
};
|
|
2438
|
+
}
|
|
2439
|
+
const parts = ref.split("/");
|
|
2440
|
+
return {
|
|
2441
|
+
projectId: parts[0],
|
|
2442
|
+
projectBranch: parts[1] || defaultBranch
|
|
2443
|
+
};
|
|
2444
|
+
}
|
|
2445
|
+
|
|
2446
|
+
// src/commands/bundle-helpers.ts
|
|
2447
|
+
import chalk8 from "chalk";
|
|
2448
|
+
import * as fs2 from "fs";
|
|
2449
|
+
import * as path2 from "path";
|
|
2450
|
+
async function streamResponseToFile(response, outFile) {
|
|
2451
|
+
const buffer = Buffer.from(await response.arrayBuffer());
|
|
2452
|
+
fs2.writeFileSync(outFile, buffer);
|
|
2453
|
+
return buffer.length;
|
|
2454
|
+
}
|
|
2455
|
+
function printLossiness(notes) {
|
|
2456
|
+
if (notes && notes.length > 0) {
|
|
2457
|
+
console.log(chalk8.yellow("Lossiness:"));
|
|
2458
|
+
for (const note of notes) {
|
|
2459
|
+
console.log(chalk8.yellow(` - ${note}`));
|
|
2460
|
+
}
|
|
2461
|
+
}
|
|
2462
|
+
}
|
|
2463
|
+
function printImportPreview(preview) {
|
|
2464
|
+
console.log(chalk8.bold(`${preview.kind} bundle \xB7 ${preview.entityCount} entities`));
|
|
2465
|
+
if (preview.projectName) {
|
|
2466
|
+
console.log(chalk8.dim(preview.projectName));
|
|
2467
|
+
}
|
|
2468
|
+
if (preview.sourceProjectId) {
|
|
2469
|
+
console.log(chalk8.dim(`from ${preview.sourceProjectId}/${preview.sourceProjectBranch}` + (preview.createdBy ? ` \xB7 by ${preview.createdBy}` : "")));
|
|
2470
|
+
}
|
|
2471
|
+
const counts = /* @__PURE__ */ new Map();
|
|
2472
|
+
for (const e of preview.entities ?? []) {
|
|
2473
|
+
counts.set(e.type, (counts.get(e.type) ?? 0) + 1);
|
|
2474
|
+
}
|
|
2475
|
+
for (const [type, count] of [...counts.entries()].sort((a, b) => a[0].localeCompare(b[0]))) {
|
|
2476
|
+
console.log(` ${type}: ${count}`);
|
|
2477
|
+
}
|
|
2478
|
+
if (preview.hasAnalysis) {
|
|
2479
|
+
console.log(" analysis recipe: included");
|
|
2480
|
+
}
|
|
2481
|
+
if (preview.skeletonCount) {
|
|
2482
|
+
console.log(` skeletons: ${preview.skeletonCount}`);
|
|
2483
|
+
}
|
|
2484
|
+
if (preview.redactedDataSourceCount) {
|
|
2485
|
+
console.log(` data sources: ${preview.redactedDataSourceCount} (credentials redacted)`);
|
|
2486
|
+
}
|
|
2487
|
+
printLossiness(preview.lossinessNotes);
|
|
2488
|
+
}
|
|
2489
|
+
function printImportResult(result) {
|
|
2490
|
+
console.log(chalk8.green(`Imported ${result.entityCount} entities, ${result.linkCount} links.`));
|
|
2491
|
+
if (result.skeletonCount) {
|
|
2492
|
+
console.log(`Skeletons: ${result.skeletonCount}`);
|
|
2493
|
+
}
|
|
2494
|
+
if (result.dataSourceCount) {
|
|
2495
|
+
console.log(`Data sources: ${result.dataSourceCount} (re-authenticate before refreshing)`);
|
|
2496
|
+
}
|
|
2497
|
+
if (result.analysisOutcome && result.analysisOutcome !== "none") {
|
|
2498
|
+
console.log(`Analysis recipe: ${result.analysisOutcome}`);
|
|
2499
|
+
}
|
|
2500
|
+
if (result.rootEntityIds.length > 0) {
|
|
2501
|
+
console.log(`Root id(s): ${result.rootEntityIds.join(", ")}`);
|
|
2502
|
+
}
|
|
2503
|
+
printLossiness(result.lossinessNotes);
|
|
2504
|
+
}
|
|
2505
|
+
async function runBundleImport(storage, projectId, projectBranch, file, options, outputFormat) {
|
|
2506
|
+
const fileBuffer = fs2.readFileSync(file);
|
|
2507
|
+
const blob = new Blob([fileBuffer]);
|
|
2508
|
+
const formData = new FormData();
|
|
2509
|
+
formData.append("content", blob, path2.basename(file));
|
|
2510
|
+
if (options.preview) {
|
|
2511
|
+
const preview = await storage.previewBundleImport(projectId, projectBranch, formData);
|
|
2512
|
+
if (outputFormat === "json") {
|
|
2513
|
+
format(preview, { format: outputFormat });
|
|
2514
|
+
return;
|
|
2515
|
+
}
|
|
2516
|
+
printImportPreview(preview);
|
|
2517
|
+
return;
|
|
2518
|
+
}
|
|
2519
|
+
const result = await storage.importBundle(projectId, projectBranch, formData, options.onConflict);
|
|
2520
|
+
if (outputFormat === "json") {
|
|
2521
|
+
format(result, { format: outputFormat });
|
|
2522
|
+
return;
|
|
2523
|
+
}
|
|
2524
|
+
printImportResult(result);
|
|
2525
|
+
}
|
|
2526
|
+
var sleep2 = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
2527
|
+
async function pollUntilFinished(storage, projectId, projectBranch, bundleId, intervalMs = 2e3, maxAttempts = 150) {
|
|
2528
|
+
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
2529
|
+
const bundles = await storage.getBundles(projectId, projectBranch);
|
|
2530
|
+
const job = bundles.find((b) => b.bundleId === bundleId);
|
|
2531
|
+
if (job && job.finished) {
|
|
2532
|
+
if (job.succeeded === false) {
|
|
2533
|
+
throw new Error(`Export failed: ${job.error || "unknown error"}`);
|
|
2534
|
+
}
|
|
2535
|
+
return job;
|
|
2536
|
+
}
|
|
2537
|
+
await sleep2(intervalMs);
|
|
2538
|
+
}
|
|
2539
|
+
throw new Error(`Export ${bundleId} did not finish within the timeout \u2014 poll it with 'diafunc notebook bundles'`);
|
|
2540
|
+
}
|
|
2541
|
+
|
|
2542
|
+
// src/commands/project/index.ts
|
|
2543
|
+
function getOutputFormat(cmd) {
|
|
2544
|
+
const config = loadConfig();
|
|
2545
|
+
const globalOpts = cmd.optsWithGlobals();
|
|
2546
|
+
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
2547
|
+
}
|
|
2548
|
+
function getOverrides(cmd) {
|
|
2549
|
+
const opts = cmd.optsWithGlobals();
|
|
2550
|
+
return { project: opts.project, branch: opts.branch };
|
|
2551
|
+
}
|
|
2552
|
+
function registerProjectCommands(program) {
|
|
2553
|
+
const project = program.command("project").description("Manage projects");
|
|
2554
|
+
project.command("list").description("List projects").option("--all", "List all projects (admin)").action(async (options, cmd) => {
|
|
2555
|
+
try {
|
|
2556
|
+
const outputFormat = getOutputFormat(cmd);
|
|
2557
|
+
const api = createApiClient();
|
|
2558
|
+
const projects = options.all ? await api.admin.getAllProjects() : await api.admin.getProjects();
|
|
2559
|
+
format(projects, {
|
|
2560
|
+
format: outputFormat,
|
|
2561
|
+
columns: ["projectId", "groupId", "visibility", "language", "active", "locked"]
|
|
2562
|
+
});
|
|
2563
|
+
} catch (error) {
|
|
2564
|
+
handleError(error);
|
|
2565
|
+
}
|
|
2566
|
+
});
|
|
2567
|
+
project.command("get").description("Get project details").argument("<projectId>", "Project ID").action(async (projectId, _options, cmd) => {
|
|
2568
|
+
try {
|
|
2569
|
+
const outputFormat = getOutputFormat(cmd);
|
|
2570
|
+
const api = createApiClient();
|
|
2571
|
+
const p = await api.admin.getProject(projectId);
|
|
2572
|
+
format(p, { format: outputFormat });
|
|
2573
|
+
} catch (error) {
|
|
2574
|
+
handleError(error);
|
|
2575
|
+
}
|
|
2576
|
+
});
|
|
2577
|
+
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) => {
|
|
2578
|
+
try {
|
|
2579
|
+
const outputFormat = getOutputFormat(cmd);
|
|
2580
|
+
const api = createApiClient();
|
|
2581
|
+
const p = await api.admin.createProject({
|
|
2582
|
+
visibility: options.visibility.toUpperCase(),
|
|
2583
|
+
language: options.language,
|
|
2584
|
+
active: true
|
|
2585
|
+
});
|
|
2586
|
+
if (outputFormat === "human") {
|
|
2587
|
+
console.log(chalk9.green("Project created."));
|
|
2588
|
+
console.log(` Project ID: ${chalk9.bold(p.projectId)}`);
|
|
2589
|
+
console.log(` Visibility: ${p.visibility}`);
|
|
2590
|
+
console.log(` Language: ${p.language}`);
|
|
2591
|
+
} else {
|
|
2592
|
+
format(p, { format: outputFormat });
|
|
2593
|
+
}
|
|
2594
|
+
} catch (error) {
|
|
2595
|
+
handleError(error);
|
|
2596
|
+
}
|
|
2597
|
+
});
|
|
2598
|
+
project.command("update").description("Update a project").argument("<projectId>", "Project ID").option("--visibility <visibility>", "PRIVATE or PUBLIC").option("--language <language>", "Project language").option("--group <groupId>", "Group ID (empty string to unset)").option("--active <bool>", "Whether the project is active (true/false)").action(async (projectId, options) => {
|
|
2176
2599
|
try {
|
|
2177
2600
|
const api = createApiClient();
|
|
2178
2601
|
const current = await api.admin.getProject(projectId);
|
|
@@ -2184,7 +2607,7 @@ function registerProjectCommands(program) {
|
|
|
2184
2607
|
...options.active !== void 0 ? { active: options.active === "true" } : {}
|
|
2185
2608
|
};
|
|
2186
2609
|
await api.admin.updateProject(updated);
|
|
2187
|
-
console.log(
|
|
2610
|
+
console.log(chalk9.green(`Project "${projectId}" updated.`));
|
|
2188
2611
|
} catch (error) {
|
|
2189
2612
|
handleError(error);
|
|
2190
2613
|
}
|
|
@@ -2206,7 +2629,7 @@ function registerProjectCommands(program) {
|
|
|
2206
2629
|
try {
|
|
2207
2630
|
const api = createApiClient();
|
|
2208
2631
|
await api.admin.deleteProject(projectId);
|
|
2209
|
-
console.log(
|
|
2632
|
+
console.log(chalk9.green(`Project "${projectId}" deleted.`));
|
|
2210
2633
|
} catch (error) {
|
|
2211
2634
|
handleError(error);
|
|
2212
2635
|
}
|
|
@@ -2215,7 +2638,7 @@ function registerProjectCommands(program) {
|
|
|
2215
2638
|
try {
|
|
2216
2639
|
const api = createApiClient();
|
|
2217
2640
|
await api.admin.lockProject(projectId);
|
|
2218
|
-
console.log(
|
|
2641
|
+
console.log(chalk9.green(`Project "${projectId}" locked.`));
|
|
2219
2642
|
} catch (error) {
|
|
2220
2643
|
handleError(error);
|
|
2221
2644
|
}
|
|
@@ -2224,7 +2647,7 @@ function registerProjectCommands(program) {
|
|
|
2224
2647
|
try {
|
|
2225
2648
|
const api = createApiClient();
|
|
2226
2649
|
await api.admin.unlockProject(projectId);
|
|
2227
|
-
console.log(
|
|
2650
|
+
console.log(chalk9.green(`Project "${projectId}" unlocked.`));
|
|
2228
2651
|
} catch (error) {
|
|
2229
2652
|
handleError(error);
|
|
2230
2653
|
}
|
|
@@ -2247,7 +2670,7 @@ function registerProjectCommands(program) {
|
|
|
2247
2670
|
try {
|
|
2248
2671
|
const api = createApiClient();
|
|
2249
2672
|
await api.admin.inviteProjectMember(projectId, userId, role.toUpperCase());
|
|
2250
|
-
console.log(
|
|
2673
|
+
console.log(chalk9.green(`Invited ${userId} to "${projectId}" as ${role.toUpperCase()}.`));
|
|
2251
2674
|
} catch (error) {
|
|
2252
2675
|
handleError(error);
|
|
2253
2676
|
}
|
|
@@ -2256,7 +2679,7 @@ function registerProjectCommands(program) {
|
|
|
2256
2679
|
try {
|
|
2257
2680
|
const api = createApiClient();
|
|
2258
2681
|
await api.admin.joinProject(projectId, userId);
|
|
2259
|
-
console.log(
|
|
2682
|
+
console.log(chalk9.green(`Joined project "${projectId}".`));
|
|
2260
2683
|
} catch (error) {
|
|
2261
2684
|
handleError(error);
|
|
2262
2685
|
}
|
|
@@ -2265,7 +2688,39 @@ function registerProjectCommands(program) {
|
|
|
2265
2688
|
try {
|
|
2266
2689
|
const api = createApiClient();
|
|
2267
2690
|
await api.admin.removeProjectMember(projectId, userId);
|
|
2268
|
-
console.log(
|
|
2691
|
+
console.log(chalk9.green(`Removed ${userId} from "${projectId}".`));
|
|
2692
|
+
} catch (error) {
|
|
2693
|
+
handleError(error);
|
|
2694
|
+
}
|
|
2695
|
+
});
|
|
2696
|
+
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) => {
|
|
2697
|
+
try {
|
|
2698
|
+
const overrides = getOverrides(cmd);
|
|
2699
|
+
const ref = parseProjectReference(project2, overrides);
|
|
2700
|
+
const api = createApiClient();
|
|
2701
|
+
const bundleId = await api.storage.exportProjectBundle(ref.projectId, ref.projectBranch);
|
|
2702
|
+
if (options.async) {
|
|
2703
|
+
console.log(chalk9.green(`Project export queued (bundle ID: ${bundleId}).`));
|
|
2704
|
+
console.log(`Poll progress: diafunc notebook bundles ${project2}`);
|
|
2705
|
+
return;
|
|
2706
|
+
}
|
|
2707
|
+
console.log(chalk9.dim(`Project export queued (bundle ID: ${bundleId}); waiting for it to finish\u2026`));
|
|
2708
|
+
const job = await pollUntilFinished(api.storage, ref.projectId, ref.projectBranch, bundleId);
|
|
2709
|
+
const response = await api.storage.getBundleContent(ref.projectId, ref.projectBranch, bundleId, job.filename);
|
|
2710
|
+
const outFile = options.out ?? "project.dfproj";
|
|
2711
|
+
const bytes = await streamResponseToFile(response, outFile);
|
|
2712
|
+
console.log(chalk9.green(`Bundle written to ${outFile} (${bytes} bytes, ${job.entityCount ?? "?"} entities).`));
|
|
2713
|
+
} catch (error) {
|
|
2714
|
+
handleError(error);
|
|
2715
|
+
}
|
|
2716
|
+
});
|
|
2717
|
+
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) => {
|
|
2718
|
+
try {
|
|
2719
|
+
const outputFormat = getOutputFormat(cmd);
|
|
2720
|
+
const overrides = getOverrides(cmd);
|
|
2721
|
+
const ref = parseProjectReference(project2, overrides);
|
|
2722
|
+
const api = createApiClient();
|
|
2723
|
+
await runBundleImport(api.storage, ref.projectId, ref.projectBranch, file, options, outputFormat);
|
|
2269
2724
|
} catch (error) {
|
|
2270
2725
|
handleError(error);
|
|
2271
2726
|
}
|
|
@@ -2273,73 +2728,28 @@ function registerProjectCommands(program) {
|
|
|
2273
2728
|
}
|
|
2274
2729
|
|
|
2275
2730
|
// src/commands/entity/index.ts
|
|
2276
|
-
import
|
|
2277
|
-
import * as
|
|
2731
|
+
import chalk11 from "chalk";
|
|
2732
|
+
import * as fs3 from "fs";
|
|
2278
2733
|
|
|
2279
|
-
// src/util/
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
}
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
if (parts.length === 1) {
|
|
2298
|
-
if (!defaultProject) {
|
|
2299
|
-
throw new Error("No default project configured. Set one with: diafunc config set defaults.project <id>");
|
|
2300
|
-
}
|
|
2301
|
-
return {
|
|
2302
|
-
projectId: defaultProject,
|
|
2303
|
-
projectBranch: defaultBranch,
|
|
2304
|
-
entityId: parts[0],
|
|
2305
|
-
entityBranch: defaultBranch
|
|
2306
|
-
};
|
|
2307
|
-
}
|
|
2308
|
-
if (parts.length === 2) {
|
|
2309
|
-
return {
|
|
2310
|
-
projectId: parts[0],
|
|
2311
|
-
projectBranch: defaultBranch,
|
|
2312
|
-
entityId: parts[1],
|
|
2313
|
-
entityBranch: defaultBranch
|
|
2314
|
-
};
|
|
2315
|
-
}
|
|
2316
|
-
if (parts.length === 3) {
|
|
2317
|
-
if (parts[1] === "") {
|
|
2318
|
-
return {
|
|
2319
|
-
projectId: parts[0],
|
|
2320
|
-
projectBranch: defaultBranch,
|
|
2321
|
-
entityId: parts[2],
|
|
2322
|
-
entityBranch: defaultBranch
|
|
2323
|
-
};
|
|
2324
|
-
}
|
|
2325
|
-
return {
|
|
2326
|
-
projectId: parts[0],
|
|
2327
|
-
projectBranch: parts[1],
|
|
2328
|
-
entityId: parts[2],
|
|
2329
|
-
entityBranch: defaultBranch
|
|
2330
|
-
};
|
|
2331
|
-
}
|
|
2332
|
-
if (parts.length === 4) {
|
|
2333
|
-
return {
|
|
2334
|
-
projectId: parts[0],
|
|
2335
|
-
projectBranch: parts[1] || defaultBranch,
|
|
2336
|
-
entityId: parts[2],
|
|
2337
|
-
entityBranch: parts[3] || defaultBranch
|
|
2338
|
-
};
|
|
2734
|
+
// src/util/confirm.ts
|
|
2735
|
+
import * as readline from "readline";
|
|
2736
|
+
import chalk10 from "chalk";
|
|
2737
|
+
async function confirmDestructive(message, opts = {}) {
|
|
2738
|
+
if (!process.stdin.isTTY || opts.yes) return;
|
|
2739
|
+
const expected = opts.resourceId ?? "yes";
|
|
2740
|
+
const hint = opts.resourceId ? `"${opts.resourceId}"` : '"yes"';
|
|
2741
|
+
console.log(chalk10.yellow(`! ${message}`));
|
|
2742
|
+
const answer = await new Promise((resolve) => {
|
|
2743
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
2744
|
+
rl.question(` Type ${hint} to confirm: `, (ans) => {
|
|
2745
|
+
rl.close();
|
|
2746
|
+
resolve(ans);
|
|
2747
|
+
});
|
|
2748
|
+
});
|
|
2749
|
+
if (answer.trim() !== expected) {
|
|
2750
|
+
console.log(chalk10.dim("Aborted."));
|
|
2751
|
+
process.exit(1);
|
|
2339
2752
|
}
|
|
2340
|
-
throw new Error(
|
|
2341
|
-
`Invalid entity reference: "${ref}". Expected format: entityId, entityId:branch, or projectId/projectBranch/entityId/entityBranch`
|
|
2342
|
-
);
|
|
2343
2753
|
}
|
|
2344
2754
|
|
|
2345
2755
|
// src/commands/entity/index.ts
|
|
@@ -2348,7 +2758,7 @@ function getOutputFormat2(cmd) {
|
|
|
2348
2758
|
const globalOpts = cmd.optsWithGlobals();
|
|
2349
2759
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
2350
2760
|
}
|
|
2351
|
-
function
|
|
2761
|
+
function getOverrides2(cmd) {
|
|
2352
2762
|
const opts = cmd.optsWithGlobals();
|
|
2353
2763
|
return { project: opts.project, branch: opts.branch };
|
|
2354
2764
|
}
|
|
@@ -2357,7 +2767,7 @@ function registerEntityCommands(program) {
|
|
|
2357
2767
|
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) => {
|
|
2358
2768
|
try {
|
|
2359
2769
|
const outputFormat = getOutputFormat2(cmd);
|
|
2360
|
-
const overrides =
|
|
2770
|
+
const overrides = getOverrides2(cmd);
|
|
2361
2771
|
const ref = parseEntityReference(projectRef + "/" + projectRef, overrides);
|
|
2362
2772
|
const api = createApiClient();
|
|
2363
2773
|
const entities = await api.storage.getLinkedEntities("FORWARD", {
|
|
@@ -2384,7 +2794,7 @@ function registerEntityCommands(program) {
|
|
|
2384
2794
|
entity.command("get").description("Get entity metadata").argument("<ref>", "Entity reference").option("--content", "Include content").action(async (ref, options, cmd) => {
|
|
2385
2795
|
try {
|
|
2386
2796
|
const outputFormat = getOutputFormat2(cmd);
|
|
2387
|
-
const overrides =
|
|
2797
|
+
const overrides = getOverrides2(cmd);
|
|
2388
2798
|
const resolved = parseEntityReference(ref, overrides);
|
|
2389
2799
|
const api = createApiClient();
|
|
2390
2800
|
const e = await api.storage.getEntity(resolved, options.content);
|
|
@@ -2412,13 +2822,14 @@ function registerEntityCommands(program) {
|
|
|
2412
2822
|
handleError(error);
|
|
2413
2823
|
}
|
|
2414
2824
|
});
|
|
2415
|
-
entity.command("delete").description("Delete an entity").argument("<ref>", "Entity reference").action(async (ref,
|
|
2825
|
+
entity.command("delete").description("Delete an entity").argument("<ref>", "Entity reference").option("-y, --yes", "Skip confirmation prompt (for CI / scripted use)").action(async (ref, options, cmd) => {
|
|
2416
2826
|
try {
|
|
2417
|
-
|
|
2827
|
+
await confirmDestructive(`This will permanently delete entity "${ref}".`, { yes: options.yes, resourceId: ref });
|
|
2828
|
+
const overrides = getOverrides2(cmd);
|
|
2418
2829
|
const resolved = parseEntityReference(ref, overrides);
|
|
2419
2830
|
const api = createApiClient();
|
|
2420
2831
|
await api.storage.deleteEntity(resolved);
|
|
2421
|
-
console.log(
|
|
2832
|
+
console.log(chalk11.green(`Entity "${resolved.entityId}" deleted.`));
|
|
2422
2833
|
} catch (error) {
|
|
2423
2834
|
handleError(error);
|
|
2424
2835
|
}
|
|
@@ -2426,7 +2837,7 @@ function registerEntityCommands(program) {
|
|
|
2426
2837
|
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) => {
|
|
2427
2838
|
try {
|
|
2428
2839
|
const outputFormat = getOutputFormat2(cmd);
|
|
2429
|
-
const overrides =
|
|
2840
|
+
const overrides = getOverrides2(cmd);
|
|
2430
2841
|
const resolved = parseEntityReference(ref, overrides);
|
|
2431
2842
|
const api = createApiClient();
|
|
2432
2843
|
if (options.from && options.to) {
|
|
@@ -2455,22 +2866,22 @@ function registerEntityCommands(program) {
|
|
|
2455
2866
|
});
|
|
2456
2867
|
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) => {
|
|
2457
2868
|
try {
|
|
2458
|
-
const overrides =
|
|
2869
|
+
const overrides = getOverrides2(cmd);
|
|
2459
2870
|
const resolved = parseEntityReference(ref, overrides);
|
|
2460
2871
|
const api = createApiClient();
|
|
2461
2872
|
await api.storage.revertEntity(resolved, parseInt(version, 10));
|
|
2462
|
-
console.log(
|
|
2873
|
+
console.log(chalk11.green(`Entity "${resolved.entityId}" reverted to version ${version}.`));
|
|
2463
2874
|
} catch (error) {
|
|
2464
2875
|
handleError(error);
|
|
2465
2876
|
}
|
|
2466
2877
|
});
|
|
2467
2878
|
entity.command("rename").description("Rename an entity").argument("<ref>", "Entity reference").argument("<newId>", "New entity ID").action(async (ref, newId, _options, cmd) => {
|
|
2468
2879
|
try {
|
|
2469
|
-
const overrides =
|
|
2880
|
+
const overrides = getOverrides2(cmd);
|
|
2470
2881
|
const resolved = parseEntityReference(ref, overrides);
|
|
2471
2882
|
const api = createApiClient();
|
|
2472
2883
|
await api.storage.renameEntity(resolved, newId);
|
|
2473
|
-
console.log(
|
|
2884
|
+
console.log(chalk11.green(`Entity renamed from "${resolved.entityId}" to "${newId}".`));
|
|
2474
2885
|
} catch (error) {
|
|
2475
2886
|
handleError(error);
|
|
2476
2887
|
}
|
|
@@ -2478,14 +2889,14 @@ function registerEntityCommands(program) {
|
|
|
2478
2889
|
const content = entity.command("content").description("Manage entity content");
|
|
2479
2890
|
content.command("get").description("Download entity content").argument("<ref>", "Entity reference").option("--out <file>", "Output file (defaults to stdout)").action(async (ref, options, cmd) => {
|
|
2480
2891
|
try {
|
|
2481
|
-
const overrides =
|
|
2892
|
+
const overrides = getOverrides2(cmd);
|
|
2482
2893
|
const resolved = parseEntityReference(ref, overrides);
|
|
2483
2894
|
const api = createApiClient();
|
|
2484
2895
|
const response = await api.storage.getEntityContent(resolved);
|
|
2485
2896
|
if (options.out) {
|
|
2486
2897
|
const buffer = Buffer.from(await response.arrayBuffer());
|
|
2487
|
-
|
|
2488
|
-
console.log(
|
|
2898
|
+
fs3.writeFileSync(options.out, buffer);
|
|
2899
|
+
console.log(chalk11.green(`Content saved to ${options.out}`));
|
|
2489
2900
|
} else {
|
|
2490
2901
|
const text = await response.text();
|
|
2491
2902
|
process.stdout.write(text);
|
|
@@ -2496,24 +2907,56 @@ function registerEntityCommands(program) {
|
|
|
2496
2907
|
});
|
|
2497
2908
|
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) => {
|
|
2498
2909
|
try {
|
|
2499
|
-
const overrides =
|
|
2910
|
+
const overrides = getOverrides2(cmd);
|
|
2500
2911
|
const resolved = parseEntityReference(ref, overrides);
|
|
2501
2912
|
const api = createApiClient();
|
|
2502
|
-
const fileBuffer =
|
|
2913
|
+
const fileBuffer = fs3.readFileSync(file);
|
|
2503
2914
|
const base64 = fileBuffer.toString("base64");
|
|
2504
2915
|
await api.storage.saveEntityContentBase64(resolved, base64);
|
|
2505
|
-
console.log(
|
|
2916
|
+
console.log(chalk11.green(`Content uploaded from "${file}" to entity "${resolved.entityId}".`));
|
|
2506
2917
|
} catch (error) {
|
|
2507
2918
|
handleError(error);
|
|
2508
2919
|
}
|
|
2509
2920
|
});
|
|
2510
|
-
content.command("delete").description("Delete entity content").argument("<ref>", "Entity reference").action(async (ref,
|
|
2921
|
+
content.command("delete").description("Delete entity content").argument("<ref>", "Entity reference").option("-y, --yes", "Skip confirmation prompt (for CI / scripted use)").action(async (ref, options, cmd) => {
|
|
2511
2922
|
try {
|
|
2512
|
-
|
|
2923
|
+
await confirmDestructive(`This will permanently delete the content of entity "${ref}".`, { yes: options.yes, resourceId: ref });
|
|
2924
|
+
const overrides = getOverrides2(cmd);
|
|
2513
2925
|
const resolved = parseEntityReference(ref, overrides);
|
|
2514
2926
|
const api = createApiClient();
|
|
2515
2927
|
await api.storage.deleteEntityContent(resolved);
|
|
2516
|
-
console.log(
|
|
2928
|
+
console.log(chalk11.green(`Content deleted from entity "${resolved.entityId}".`));
|
|
2929
|
+
} catch (error) {
|
|
2930
|
+
handleError(error);
|
|
2931
|
+
}
|
|
2932
|
+
});
|
|
2933
|
+
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) => {
|
|
2934
|
+
try {
|
|
2935
|
+
const overrides = getOverrides2(cmd);
|
|
2936
|
+
const ref = parseProjectReference(project, overrides);
|
|
2937
|
+
const api = createApiClient();
|
|
2938
|
+
const request = { rootEntityIds: entityIds, dataFormat: options.data };
|
|
2939
|
+
if (options.async) {
|
|
2940
|
+
const bundleId = await api.storage.exportEntitySubset(ref.projectId, ref.projectBranch, request);
|
|
2941
|
+
console.log(chalk11.green(`Export queued (bundle ID: ${bundleId}).`));
|
|
2942
|
+
console.log(`Poll progress: diafunc notebook bundles ${project}`);
|
|
2943
|
+
return;
|
|
2944
|
+
}
|
|
2945
|
+
const response = await api.storage.streamEntitySubset(ref.projectId, ref.projectBranch, request);
|
|
2946
|
+
const outFile = options.out ?? "entities.dfset";
|
|
2947
|
+
const bytes = await streamResponseToFile(response, outFile);
|
|
2948
|
+
console.log(chalk11.green(`Bundle written to ${outFile} (${bytes} bytes, ${entityIds.length} entity(ies)).`));
|
|
2949
|
+
} catch (error) {
|
|
2950
|
+
handleError(error);
|
|
2951
|
+
}
|
|
2952
|
+
});
|
|
2953
|
+
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) => {
|
|
2954
|
+
try {
|
|
2955
|
+
const outputFormat = getOutputFormat2(cmd);
|
|
2956
|
+
const overrides = getOverrides2(cmd);
|
|
2957
|
+
const ref = parseProjectReference(project, overrides);
|
|
2958
|
+
const api = createApiClient();
|
|
2959
|
+
await runBundleImport(api.storage, ref.projectId, ref.projectBranch, file, options, outputFormat);
|
|
2517
2960
|
} catch (error) {
|
|
2518
2961
|
handleError(error);
|
|
2519
2962
|
}
|
|
@@ -2521,13 +2964,13 @@ function registerEntityCommands(program) {
|
|
|
2521
2964
|
}
|
|
2522
2965
|
|
|
2523
2966
|
// src/commands/link/index.ts
|
|
2524
|
-
import
|
|
2967
|
+
import chalk12 from "chalk";
|
|
2525
2968
|
function getOutputFormat3(cmd) {
|
|
2526
2969
|
const config = loadConfig();
|
|
2527
2970
|
const globalOpts = cmd.optsWithGlobals();
|
|
2528
2971
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
2529
2972
|
}
|
|
2530
|
-
function
|
|
2973
|
+
function getOverrides3(cmd) {
|
|
2531
2974
|
const opts = cmd.optsWithGlobals();
|
|
2532
2975
|
return { project: opts.project, branch: opts.branch };
|
|
2533
2976
|
}
|
|
@@ -2536,7 +2979,7 @@ function registerLinkCommands(program) {
|
|
|
2536
2979
|
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) => {
|
|
2537
2980
|
try {
|
|
2538
2981
|
const outputFormat = getOutputFormat3(cmd);
|
|
2539
|
-
const overrides =
|
|
2982
|
+
const overrides = getOverrides3(cmd);
|
|
2540
2983
|
const resolved = parseEntityReference(ref, overrides);
|
|
2541
2984
|
const api = createApiClient();
|
|
2542
2985
|
const direction = options.direction.toUpperCase();
|
|
@@ -2558,7 +3001,7 @@ function registerLinkCommands(program) {
|
|
|
2558
3001
|
});
|
|
2559
3002
|
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) => {
|
|
2560
3003
|
try {
|
|
2561
|
-
const overrides =
|
|
3004
|
+
const overrides = getOverrides3(cmd);
|
|
2562
3005
|
const source = parseEntityReference(sourceRef, overrides);
|
|
2563
3006
|
const target = parseEntityReference(targetRef, overrides);
|
|
2564
3007
|
const api = createApiClient();
|
|
@@ -2571,14 +3014,14 @@ function registerLinkCommands(program) {
|
|
|
2571
3014
|
target.entityId,
|
|
2572
3015
|
target.entityBranch
|
|
2573
3016
|
);
|
|
2574
|
-
console.log(
|
|
3017
|
+
console.log(chalk12.green(`Link "${linkId}" created: ${source.entityId} \u2192 ${target.entityId}`));
|
|
2575
3018
|
} catch (error) {
|
|
2576
3019
|
handleError(error);
|
|
2577
3020
|
}
|
|
2578
3021
|
});
|
|
2579
3022
|
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) => {
|
|
2580
3023
|
try {
|
|
2581
|
-
const overrides =
|
|
3024
|
+
const overrides = getOverrides3(cmd);
|
|
2582
3025
|
const source = parseEntityReference(sourceRef, overrides);
|
|
2583
3026
|
const api = createApiClient();
|
|
2584
3027
|
if (targetRef) {
|
|
@@ -2592,7 +3035,7 @@ function registerLinkCommands(program) {
|
|
|
2592
3035
|
target.entityId,
|
|
2593
3036
|
target.entityBranch
|
|
2594
3037
|
);
|
|
2595
|
-
console.log(
|
|
3038
|
+
console.log(chalk12.green(`Link "${linkId}" deleted: ${source.entityId} \u2192 ${target.entityId}`));
|
|
2596
3039
|
} else {
|
|
2597
3040
|
await api.storage.deleteLink(
|
|
2598
3041
|
source.projectId,
|
|
@@ -2601,7 +3044,7 @@ function registerLinkCommands(program) {
|
|
|
2601
3044
|
source.entityBranch,
|
|
2602
3045
|
linkId
|
|
2603
3046
|
);
|
|
2604
|
-
console.log(
|
|
3047
|
+
console.log(chalk12.green(`All links with ID "${linkId}" from "${source.entityId}" deleted.`));
|
|
2605
3048
|
}
|
|
2606
3049
|
} catch (error) {
|
|
2607
3050
|
handleError(error);
|
|
@@ -2610,13 +3053,13 @@ function registerLinkCommands(program) {
|
|
|
2610
3053
|
}
|
|
2611
3054
|
|
|
2612
3055
|
// src/commands/event/index.ts
|
|
2613
|
-
import
|
|
3056
|
+
import chalk13 from "chalk";
|
|
2614
3057
|
function getOutputFormat4(cmd) {
|
|
2615
3058
|
const config = loadConfig();
|
|
2616
3059
|
const globalOpts = cmd.optsWithGlobals();
|
|
2617
3060
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
2618
3061
|
}
|
|
2619
|
-
function
|
|
3062
|
+
function getOverrides4(cmd) {
|
|
2620
3063
|
const opts = cmd.optsWithGlobals();
|
|
2621
3064
|
return { project: opts.project, branch: opts.branch };
|
|
2622
3065
|
}
|
|
@@ -2625,7 +3068,7 @@ function registerEventCommands(program) {
|
|
|
2625
3068
|
event.command("list").description("List events for an entity").argument("<ref>", "Entity reference").action(async (ref, _options, cmd) => {
|
|
2626
3069
|
try {
|
|
2627
3070
|
const outputFormat = getOutputFormat4(cmd);
|
|
2628
|
-
const overrides =
|
|
3071
|
+
const overrides = getOverrides4(cmd);
|
|
2629
3072
|
const resolved = parseEntityReference(ref, overrides);
|
|
2630
3073
|
const api = createApiClient();
|
|
2631
3074
|
const events = await api.storage.getEvents(resolved);
|
|
@@ -2647,7 +3090,7 @@ function registerEventCommands(program) {
|
|
|
2647
3090
|
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) => {
|
|
2648
3091
|
try {
|
|
2649
3092
|
const outputFormat = getOutputFormat4(cmd);
|
|
2650
|
-
const overrides =
|
|
3093
|
+
const overrides = getOverrides4(cmd);
|
|
2651
3094
|
const resolved = parseEntityReference(ref, overrides);
|
|
2652
3095
|
const api = createApiClient();
|
|
2653
3096
|
const event2 = await api.storage.getEvent(resolved, eventId, occurrenceId);
|
|
@@ -2658,8 +3101,8 @@ function registerEventCommands(program) {
|
|
|
2658
3101
|
});
|
|
2659
3102
|
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) => {
|
|
2660
3103
|
try {
|
|
2661
|
-
const
|
|
2662
|
-
const body = file ?
|
|
3104
|
+
const fs14 = await import("fs");
|
|
3105
|
+
const body = file ? fs14.readFileSync(file, "utf-8") : await new Promise((resolve, reject) => {
|
|
2663
3106
|
let data = "";
|
|
2664
3107
|
process.stdin.setEncoding("utf-8");
|
|
2665
3108
|
process.stdin.on("data", (chunk) => {
|
|
@@ -2672,7 +3115,7 @@ function registerEventCommands(program) {
|
|
|
2672
3115
|
const api = createApiClient();
|
|
2673
3116
|
const arr = Array.isArray(events) ? events : [events];
|
|
2674
3117
|
await api.storage.createEvents(arr);
|
|
2675
|
-
console.log(
|
|
3118
|
+
console.log(chalk13.green(`${arr.length} event(s) created.`));
|
|
2676
3119
|
} catch (error) {
|
|
2677
3120
|
handleError(error);
|
|
2678
3121
|
}
|
|
@@ -2695,11 +3138,11 @@ function registerEventCommands(program) {
|
|
|
2695
3138
|
});
|
|
2696
3139
|
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) => {
|
|
2697
3140
|
try {
|
|
2698
|
-
const overrides =
|
|
3141
|
+
const overrides = getOverrides4(cmd);
|
|
2699
3142
|
const resolved = parseEntityReference(ref, overrides);
|
|
2700
3143
|
const api = createApiClient();
|
|
2701
3144
|
await api.storage.deleteEvent(resolved, eventId, occurrenceId);
|
|
2702
|
-
console.log(
|
|
3145
|
+
console.log(chalk13.green(`Event "${eventId}/${occurrenceId}" deleted.`));
|
|
2703
3146
|
} catch (error) {
|
|
2704
3147
|
handleError(error);
|
|
2705
3148
|
}
|
|
@@ -2707,13 +3150,13 @@ function registerEventCommands(program) {
|
|
|
2707
3150
|
}
|
|
2708
3151
|
|
|
2709
3152
|
// src/commands/branch/index.ts
|
|
2710
|
-
import
|
|
3153
|
+
import chalk14 from "chalk";
|
|
2711
3154
|
function getOutputFormat5(cmd) {
|
|
2712
3155
|
const config = loadConfig();
|
|
2713
3156
|
const globalOpts = cmd.optsWithGlobals();
|
|
2714
3157
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
2715
3158
|
}
|
|
2716
|
-
function
|
|
3159
|
+
function getOverrides5(cmd) {
|
|
2717
3160
|
const opts = cmd.optsWithGlobals();
|
|
2718
3161
|
return { project: opts.project, branch: opts.branch };
|
|
2719
3162
|
}
|
|
@@ -2722,11 +3165,11 @@ function registerBranchCommands(program) {
|
|
|
2722
3165
|
branch.command("list").description("List branches for a project").argument("[projectId]", "Project ID (uses default if omitted)").action(async (projectId, _options, cmd) => {
|
|
2723
3166
|
try {
|
|
2724
3167
|
const outputFormat = getOutputFormat5(cmd);
|
|
2725
|
-
const overrides =
|
|
3168
|
+
const overrides = getOverrides5(cmd);
|
|
2726
3169
|
const config = loadConfig();
|
|
2727
3170
|
const pid = projectId ?? overrides.project ?? config.defaults.project;
|
|
2728
3171
|
if (!pid) {
|
|
2729
|
-
console.error(
|
|
3172
|
+
console.error(chalk14.red("No project specified. Pass a project ID or set defaults.project."));
|
|
2730
3173
|
process.exit(1);
|
|
2731
3174
|
}
|
|
2732
3175
|
const api = createApiClient();
|
|
@@ -2750,7 +3193,7 @@ function registerBranchCommands(program) {
|
|
|
2750
3193
|
sourceProjectBranch: options.source,
|
|
2751
3194
|
targetProjectBranch: branchName
|
|
2752
3195
|
});
|
|
2753
|
-
console.log(
|
|
3196
|
+
console.log(chalk14.green(`Branch "${branchName}" created in project "${projectId}" from "${options.source}".`));
|
|
2754
3197
|
} catch (error) {
|
|
2755
3198
|
handleError(error);
|
|
2756
3199
|
}
|
|
@@ -2759,14 +3202,14 @@ function registerBranchCommands(program) {
|
|
|
2759
3202
|
try {
|
|
2760
3203
|
const api = createApiClient();
|
|
2761
3204
|
await api.storage.deleteProjectBranch(projectId, branchName);
|
|
2762
|
-
console.log(
|
|
3205
|
+
console.log(chalk14.green(`Branch "${branchName}" deleted from project "${projectId}".`));
|
|
2763
3206
|
} catch (error) {
|
|
2764
3207
|
handleError(error);
|
|
2765
3208
|
}
|
|
2766
3209
|
});
|
|
2767
3210
|
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) => {
|
|
2768
3211
|
try {
|
|
2769
|
-
const overrides =
|
|
3212
|
+
const overrides = getOverrides5(cmd);
|
|
2770
3213
|
const source = parseEntityReference(options.source, overrides);
|
|
2771
3214
|
const targetParts = options.target.split("/");
|
|
2772
3215
|
const api = createApiClient();
|
|
@@ -2780,7 +3223,7 @@ function registerBranchCommands(program) {
|
|
|
2780
3223
|
linkId: options.linkId,
|
|
2781
3224
|
deepMerge: options.deep
|
|
2782
3225
|
});
|
|
2783
|
-
console.log(
|
|
3226
|
+
console.log(chalk14.green("Merge completed."));
|
|
2784
3227
|
} catch (error) {
|
|
2785
3228
|
handleError(error);
|
|
2786
3229
|
}
|
|
@@ -2795,7 +3238,7 @@ function registerBranchCommands(program) {
|
|
|
2795
3238
|
forkProjectName: options.name ?? forkProjectId,
|
|
2796
3239
|
forkProjectDescription: options.description
|
|
2797
3240
|
});
|
|
2798
|
-
console.log(
|
|
3241
|
+
console.log(chalk14.green(`Project "${projectId}" forked to "${forkProjectId}".`));
|
|
2799
3242
|
} catch (error) {
|
|
2800
3243
|
handleError(error);
|
|
2801
3244
|
}
|
|
@@ -2803,24 +3246,37 @@ function registerBranchCommands(program) {
|
|
|
2803
3246
|
}
|
|
2804
3247
|
|
|
2805
3248
|
// src/commands/table/index.ts
|
|
2806
|
-
import
|
|
2807
|
-
import * as
|
|
2808
|
-
import * as
|
|
3249
|
+
import chalk15 from "chalk";
|
|
3250
|
+
import * as fs4 from "fs";
|
|
3251
|
+
import * as path3 from "path";
|
|
2809
3252
|
function getOutputFormat6(cmd) {
|
|
2810
3253
|
const config = loadConfig();
|
|
2811
3254
|
const globalOpts = cmd.optsWithGlobals();
|
|
2812
3255
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
2813
3256
|
}
|
|
2814
|
-
function
|
|
3257
|
+
function getOverrides6(cmd) {
|
|
2815
3258
|
const opts = cmd.optsWithGlobals();
|
|
2816
3259
|
return { project: opts.project, branch: opts.branch };
|
|
2817
3260
|
}
|
|
3261
|
+
function deriveOutFile(entityId, extension, archive, compression) {
|
|
3262
|
+
let name = `${entityId}${extension}`;
|
|
3263
|
+
if (archive === "zip") {
|
|
3264
|
+
name += ".zip";
|
|
3265
|
+
} else if (archive === "tar") {
|
|
3266
|
+
name += ".tar";
|
|
3267
|
+
}
|
|
3268
|
+
if (archive !== "zip" && compression) {
|
|
3269
|
+
const suffix = { gzip: ".gz", bzip2: ".bz2", xz: ".xz", zstd: ".zst" };
|
|
3270
|
+
name += suffix[compression] ?? "";
|
|
3271
|
+
}
|
|
3272
|
+
return name;
|
|
3273
|
+
}
|
|
2818
3274
|
function registerTableCommands(program) {
|
|
2819
3275
|
const table = program.command("table").description("Manage tables");
|
|
2820
3276
|
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) => {
|
|
2821
3277
|
try {
|
|
2822
3278
|
const outputFormat = getOutputFormat6(cmd);
|
|
2823
|
-
const overrides =
|
|
3279
|
+
const overrides = getOverrides6(cmd);
|
|
2824
3280
|
const resolved = parseEntityReference(ref, overrides);
|
|
2825
3281
|
const api = createApiClient();
|
|
2826
3282
|
const request = {};
|
|
@@ -2860,29 +3316,28 @@ function registerTableCommands(program) {
|
|
|
2860
3316
|
console.log(colNames.map((c) => row2[c] ?? "").join(" "));
|
|
2861
3317
|
}
|
|
2862
3318
|
} else {
|
|
2863
|
-
console.log(
|
|
3319
|
+
console.log(chalk15.dim(`${snapshot.rows.length} rows \xD7 ${snapshot.columns.length} columns`));
|
|
2864
3320
|
format(tableData, { format: outputFormat, columns: colNames });
|
|
2865
3321
|
}
|
|
2866
3322
|
} catch (error) {
|
|
2867
3323
|
handleError(error);
|
|
2868
3324
|
}
|
|
2869
3325
|
});
|
|
2870
|
-
table.command("import").description("Import data from a
|
|
3326
|
+
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) => {
|
|
2871
3327
|
try {
|
|
2872
|
-
const overrides =
|
|
3328
|
+
const overrides = getOverrides6(cmd);
|
|
2873
3329
|
const resolved = parseEntityReference(ref, overrides);
|
|
2874
|
-
if (!
|
|
2875
|
-
console.error(
|
|
3330
|
+
if (!fs4.existsSync(file)) {
|
|
3331
|
+
console.error(chalk15.red(`File not found: ${file}`));
|
|
2876
3332
|
process.exit(1);
|
|
2877
3333
|
}
|
|
2878
3334
|
const api = createApiClient();
|
|
2879
|
-
const fileBuffer =
|
|
3335
|
+
const fileBuffer = fs4.readFileSync(file);
|
|
2880
3336
|
const blob = new Blob([fileBuffer]);
|
|
2881
3337
|
const formData = new FormData();
|
|
2882
|
-
formData.append("content", blob,
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
const importId = await api.storage.importTable(resolved, formData, columnHeaders);
|
|
3338
|
+
formData.append("content", blob, path3.basename(file));
|
|
3339
|
+
console.log(`Importing ${path3.basename(file)} ...`);
|
|
3340
|
+
const importId = await api.storage.importTable(resolved, formData, options.selection);
|
|
2886
3341
|
console.log(`Import started (ID: ${importId}). Waiting for completion ...`);
|
|
2887
3342
|
const pollInterval = 1e3;
|
|
2888
3343
|
const maxAttempts = 300;
|
|
@@ -2891,40 +3346,182 @@ function registerTableCommands(program) {
|
|
|
2891
3346
|
const imp = await api.storage.getImport(resolved, importId);
|
|
2892
3347
|
if (imp.finished !== null) {
|
|
2893
3348
|
if (imp.succeeded) {
|
|
2894
|
-
console.log(
|
|
3349
|
+
console.log(chalk15.green(`Import completed successfully (${imp.duration}ms).`));
|
|
2895
3350
|
} else {
|
|
2896
|
-
console.error(
|
|
3351
|
+
console.error(chalk15.red(`Import failed: ${imp.error}`));
|
|
2897
3352
|
process.exit(1);
|
|
2898
3353
|
}
|
|
2899
3354
|
return;
|
|
2900
3355
|
}
|
|
2901
3356
|
}
|
|
2902
|
-
console.error(
|
|
3357
|
+
console.error(chalk15.yellow("Import still in progress. Check status later."));
|
|
2903
3358
|
} catch (error) {
|
|
2904
3359
|
handleError(error);
|
|
2905
3360
|
}
|
|
2906
3361
|
});
|
|
2907
|
-
table.command("
|
|
3362
|
+
table.command("import-formats").description("List supported import formats").action(async (_options, cmd) => {
|
|
2908
3363
|
try {
|
|
2909
|
-
const
|
|
3364
|
+
const outputFormat = getOutputFormat6(cmd);
|
|
3365
|
+
const api = createApiClient();
|
|
3366
|
+
const response = await api.storage.getSupportedImportFormats();
|
|
3367
|
+
if (outputFormat === "json") {
|
|
3368
|
+
format(response, { format: outputFormat });
|
|
3369
|
+
return;
|
|
3370
|
+
}
|
|
3371
|
+
const rows = response.formats.map((f) => ({
|
|
3372
|
+
id: f.id,
|
|
3373
|
+
displayName: f.displayName,
|
|
3374
|
+
category: f.category,
|
|
3375
|
+
extensions: f.extensions.join(", "),
|
|
3376
|
+
mimeTypes: f.mimeTypes.join(", "),
|
|
3377
|
+
multiTable: f.multiTable ? "yes" : "no",
|
|
3378
|
+
userDefined: f.userDefined ? "yes" : "no"
|
|
3379
|
+
}));
|
|
3380
|
+
format(rows, { format: outputFormat, columns: ["id", "displayName", "category", "extensions", "mimeTypes", "multiTable", "userDefined"] });
|
|
3381
|
+
} catch (error) {
|
|
3382
|
+
handleError(error);
|
|
3383
|
+
}
|
|
3384
|
+
});
|
|
3385
|
+
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) => {
|
|
3386
|
+
try {
|
|
3387
|
+
const overrides = getOverrides6(cmd);
|
|
2910
3388
|
const resolved = parseEntityReference(ref, overrides);
|
|
2911
3389
|
const api = createApiClient();
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
if (
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
}
|
|
2918
|
-
|
|
2919
|
-
|
|
3390
|
+
const formats = await api.storage.getSupportedExportFormats();
|
|
3391
|
+
const format2 = formats.formats.find((f) => f.id.toLowerCase() === fmt.toLowerCase());
|
|
3392
|
+
if (!format2) {
|
|
3393
|
+
console.error(chalk15.red(`Unknown format: "${fmt}". Run \`diafunc table export-formats\` to see the catalogue.`));
|
|
3394
|
+
process.exit(1);
|
|
3395
|
+
}
|
|
3396
|
+
if (options.compression && !formats.compressionAlgorithms.includes(options.compression)) {
|
|
3397
|
+
console.error(chalk15.red(`Unknown compression: "${options.compression}". Use one of ${formats.compressionAlgorithms.join(", ")}.`));
|
|
3398
|
+
process.exit(1);
|
|
3399
|
+
}
|
|
3400
|
+
if (options.archive && !formats.archiveAlgorithms.includes(options.archive)) {
|
|
3401
|
+
console.error(chalk15.red(`Unknown archive: "${options.archive}". Use one of ${formats.archiveAlgorithms.join(", ")}.`));
|
|
3402
|
+
process.exit(1);
|
|
3403
|
+
}
|
|
3404
|
+
const exportOptions = {
|
|
3405
|
+
compression: options.compression,
|
|
3406
|
+
archive: options.archive
|
|
3407
|
+
};
|
|
3408
|
+
if (options.rows) {
|
|
3409
|
+
const [from, to] = String(options.rows).split(":").map(Number);
|
|
3410
|
+
if (!isNaN(from)) exportOptions.fromRow = from;
|
|
3411
|
+
if (!isNaN(to)) exportOptions.toRow = to;
|
|
3412
|
+
}
|
|
3413
|
+
if (options.cols) {
|
|
3414
|
+
const [from, to] = String(options.cols).split(":").map(Number);
|
|
3415
|
+
if (!isNaN(from)) exportOptions.fromColumn = from;
|
|
3416
|
+
if (!isNaN(to)) exportOptions.toColumn = to;
|
|
3417
|
+
}
|
|
3418
|
+
const csvLike = format2.id === "csv" || format2.id === "tsv";
|
|
3419
|
+
if (csvLike) {
|
|
3420
|
+
if (options.delimiter !== void 0) exportOptions.delimiter = options.delimiter;
|
|
3421
|
+
if (options.quote !== void 0) exportOptions.quote = options.quote;
|
|
3422
|
+
if (options.null !== void 0) exportOptions.nullValue = options.null;
|
|
3423
|
+
if (options.quoteAll === false) exportOptions.quoteAll = false;
|
|
3424
|
+
}
|
|
3425
|
+
const useStream = !options.async;
|
|
3426
|
+
if (useStream) {
|
|
3427
|
+
const response = await api.storage.streamExport(resolved, format2.id, exportOptions);
|
|
3428
|
+
const outFile = options.out ?? deriveOutFile(resolved.entityId, format2.extension, options.archive, options.compression);
|
|
3429
|
+
const buffer = Buffer.from(await response.arrayBuffer());
|
|
3430
|
+
fs4.writeFileSync(outFile, buffer);
|
|
3431
|
+
console.log(chalk15.green(`Table streamed to ${outFile}`));
|
|
2920
3432
|
} else {
|
|
2921
|
-
|
|
3433
|
+
const exportId = await api.storage.exportTable(resolved, format2.id, exportOptions);
|
|
3434
|
+
console.log(chalk15.green(`Export queued (ID: ${exportId}).`));
|
|
3435
|
+
console.log(`Poll progress: diafunc table exports get ${exportId} --ref ${ref}`);
|
|
3436
|
+
}
|
|
3437
|
+
} catch (error) {
|
|
3438
|
+
handleError(error);
|
|
3439
|
+
}
|
|
3440
|
+
});
|
|
3441
|
+
table.command("export-formats").description("List supported export formats").action(async (_options, cmd) => {
|
|
3442
|
+
try {
|
|
3443
|
+
const outputFormat = getOutputFormat6(cmd);
|
|
3444
|
+
const api = createApiClient();
|
|
3445
|
+
const response = await api.storage.getSupportedExportFormats();
|
|
3446
|
+
if (outputFormat === "json") {
|
|
3447
|
+
format(response, { format: outputFormat });
|
|
3448
|
+
return;
|
|
3449
|
+
}
|
|
3450
|
+
const rows = response.formats.map((f) => ({
|
|
3451
|
+
id: f.id,
|
|
3452
|
+
displayName: f.displayName,
|
|
3453
|
+
category: f.category,
|
|
3454
|
+
extension: f.extension,
|
|
3455
|
+
mimeType: f.mimeType,
|
|
3456
|
+
knownLimitations: f.knownLimitations.join(" / ")
|
|
3457
|
+
}));
|
|
3458
|
+
format(rows, { format: outputFormat, columns: ["id", "displayName", "category", "extension", "mimeType", "knownLimitations"] });
|
|
3459
|
+
console.log(chalk15.dim(`Compression: ${response.compressionAlgorithms.join(", ")}`));
|
|
3460
|
+
console.log(chalk15.dim(`Archive: ${response.archiveAlgorithms.join(", ")}`));
|
|
3461
|
+
} catch (error) {
|
|
3462
|
+
handleError(error);
|
|
3463
|
+
}
|
|
3464
|
+
});
|
|
3465
|
+
const exportsCmd = table.command("exports").description("Track and download async table exports");
|
|
3466
|
+
exportsCmd.command("list").description("List async exports for a table entity").argument("<ref>", "Table entity reference").action(async (ref, _options, cmd) => {
|
|
3467
|
+
try {
|
|
3468
|
+
const outputFormat = getOutputFormat6(cmd);
|
|
3469
|
+
const overrides = getOverrides6(cmd);
|
|
3470
|
+
const resolved = parseEntityReference(ref, overrides);
|
|
3471
|
+
const api = createApiClient();
|
|
3472
|
+
const exports = await api.storage.listExports(resolved);
|
|
3473
|
+
if (outputFormat === "json") {
|
|
3474
|
+
format(exports, { format: outputFormat });
|
|
3475
|
+
return;
|
|
3476
|
+
}
|
|
3477
|
+
if (exports.length === 0) {
|
|
3478
|
+
console.log(chalk15.dim("No exports found."));
|
|
3479
|
+
return;
|
|
3480
|
+
}
|
|
3481
|
+
const rows = exports.map((e) => ({
|
|
3482
|
+
exportId: e.exportId,
|
|
3483
|
+
filename: e.filename,
|
|
3484
|
+
progress: `${Math.round((e.progress ?? 0) * 100)}%`,
|
|
3485
|
+
succeeded: e.succeeded === true ? "yes" : e.succeeded === false ? "no" : "\u2014",
|
|
3486
|
+
duration: e.duration != null ? `${e.duration}ms` : "\u2014",
|
|
3487
|
+
error: e.error ?? ""
|
|
3488
|
+
}));
|
|
3489
|
+
format(rows, { format: outputFormat, columns: ["exportId", "filename", "progress", "succeeded", "duration", "error"] });
|
|
3490
|
+
} catch (error) {
|
|
3491
|
+
handleError(error);
|
|
3492
|
+
}
|
|
3493
|
+
});
|
|
3494
|
+
exportsCmd.command("get").description("Get async export status; download the file once the export has succeeded").argument("<exportId>", "Export ID returned by `table export --async`").requiredOption("--ref <ref>", "Table entity reference").option("--out <file>", "Output file path (defaults to the original export filename)").action(async (exportId, options, cmd) => {
|
|
3495
|
+
try {
|
|
3496
|
+
const outputFormat = getOutputFormat6(cmd);
|
|
3497
|
+
const overrides = getOverrides6(cmd);
|
|
3498
|
+
const resolved = parseEntityReference(options.ref, overrides);
|
|
3499
|
+
const api = createApiClient();
|
|
3500
|
+
const exports = await api.storage.listExports(resolved);
|
|
3501
|
+
const exp = exports.find((e) => e.exportId === exportId);
|
|
3502
|
+
if (!exp) {
|
|
3503
|
+
console.error(chalk15.red(`Export ${exportId} not found for ref ${options.ref}.`));
|
|
3504
|
+
process.exit(1);
|
|
3505
|
+
}
|
|
3506
|
+
if (outputFormat === "json") {
|
|
3507
|
+
format(exp, { format: outputFormat });
|
|
3508
|
+
return;
|
|
3509
|
+
}
|
|
3510
|
+
if (exp.finished === null) {
|
|
3511
|
+
const pct = Math.round((exp.progress ?? 0) * 100);
|
|
3512
|
+
console.log(chalk15.dim(`Export in progress: ${pct}% \u2014 check again later.`));
|
|
3513
|
+
return;
|
|
3514
|
+
}
|
|
3515
|
+
if (!exp.succeeded) {
|
|
3516
|
+
console.error(chalk15.red(`Export failed: ${exp.error}`));
|
|
2922
3517
|
process.exit(1);
|
|
2923
3518
|
}
|
|
2924
|
-
const outFile = options.out ??
|
|
3519
|
+
const outFile = options.out ?? exp.filename;
|
|
3520
|
+
console.log(`Downloading ${exp.filename} ...`);
|
|
3521
|
+
const response = await api.storage.downloadExport(resolved, exportId, exp.filename);
|
|
2925
3522
|
const buffer = Buffer.from(await response.arrayBuffer());
|
|
2926
|
-
|
|
2927
|
-
console.log(
|
|
3523
|
+
fs4.writeFileSync(outFile, buffer);
|
|
3524
|
+
console.log(chalk15.green(`Export saved to ${outFile}`));
|
|
2928
3525
|
} catch (error) {
|
|
2929
3526
|
handleError(error);
|
|
2930
3527
|
}
|
|
@@ -2932,22 +3529,44 @@ function registerTableCommands(program) {
|
|
|
2932
3529
|
const row = table.command("row").description("Manage table rows");
|
|
2933
3530
|
row.command("add").description("Append a row to a table").argument("<ref>", "Table entity reference").action(async (ref, _options, cmd) => {
|
|
2934
3531
|
try {
|
|
2935
|
-
const overrides =
|
|
3532
|
+
const overrides = getOverrides6(cmd);
|
|
2936
3533
|
const resolved = parseEntityReference(ref, overrides);
|
|
2937
3534
|
const api = createApiClient();
|
|
2938
3535
|
await api.storage.appendRow(resolved);
|
|
2939
|
-
console.log(
|
|
3536
|
+
console.log(chalk15.green("Row appended."));
|
|
2940
3537
|
} catch (error) {
|
|
2941
3538
|
handleError(error);
|
|
2942
3539
|
}
|
|
2943
3540
|
});
|
|
2944
|
-
row.command("
|
|
3541
|
+
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) => {
|
|
2945
3542
|
try {
|
|
2946
|
-
const overrides =
|
|
3543
|
+
const overrides = getOverrides6(cmd);
|
|
3544
|
+
const resolved = parseEntityReference(ref, overrides);
|
|
3545
|
+
const api = createApiClient();
|
|
3546
|
+
await api.storage.insertRow(resolved, parseInt(index, 10));
|
|
3547
|
+
console.log(chalk15.green(`Row inserted at index ${index}.`));
|
|
3548
|
+
} catch (error) {
|
|
3549
|
+
handleError(error);
|
|
3550
|
+
}
|
|
3551
|
+
});
|
|
3552
|
+
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) => {
|
|
3553
|
+
try {
|
|
3554
|
+
const overrides = getOverrides6(cmd);
|
|
3555
|
+
const resolved = parseEntityReference(ref, overrides);
|
|
3556
|
+
const api = createApiClient();
|
|
3557
|
+
await api.storage.removeRow(resolved, parseInt(index, 10));
|
|
3558
|
+
console.log(chalk15.green(`Row ${index} removed.`));
|
|
3559
|
+
} catch (error) {
|
|
3560
|
+
handleError(error);
|
|
3561
|
+
}
|
|
3562
|
+
});
|
|
3563
|
+
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) => {
|
|
3564
|
+
try {
|
|
3565
|
+
const overrides = getOverrides6(cmd);
|
|
2947
3566
|
const resolved = parseEntityReference(ref, overrides);
|
|
2948
3567
|
const api = createApiClient();
|
|
2949
3568
|
await api.storage.deleteRow(resolved, parseInt(index, 10));
|
|
2950
|
-
console.log(
|
|
3569
|
+
console.log(chalk15.green(`Row ${index} deleted.`));
|
|
2951
3570
|
} catch (error) {
|
|
2952
3571
|
handleError(error);
|
|
2953
3572
|
}
|
|
@@ -2955,22 +3574,44 @@ function registerTableCommands(program) {
|
|
|
2955
3574
|
const column = table.command("column").description("Manage table columns");
|
|
2956
3575
|
column.command("add").description("Append a column to a table").argument("<ref>", "Table entity reference").action(async (ref, _options, cmd) => {
|
|
2957
3576
|
try {
|
|
2958
|
-
const overrides =
|
|
3577
|
+
const overrides = getOverrides6(cmd);
|
|
2959
3578
|
const resolved = parseEntityReference(ref, overrides);
|
|
2960
3579
|
const api = createApiClient();
|
|
2961
3580
|
await api.storage.appendColumn(resolved);
|
|
2962
|
-
console.log(
|
|
3581
|
+
console.log(chalk15.green("Column appended."));
|
|
2963
3582
|
} catch (error) {
|
|
2964
3583
|
handleError(error);
|
|
2965
3584
|
}
|
|
2966
3585
|
});
|
|
2967
|
-
column.command("
|
|
3586
|
+
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) => {
|
|
2968
3587
|
try {
|
|
2969
|
-
const overrides =
|
|
3588
|
+
const overrides = getOverrides6(cmd);
|
|
3589
|
+
const resolved = parseEntityReference(ref, overrides);
|
|
3590
|
+
const api = createApiClient();
|
|
3591
|
+
await api.storage.insertColumn(resolved, parseInt(index, 10));
|
|
3592
|
+
console.log(chalk15.green(`Column inserted at index ${index}.`));
|
|
3593
|
+
} catch (error) {
|
|
3594
|
+
handleError(error);
|
|
3595
|
+
}
|
|
3596
|
+
});
|
|
3597
|
+
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) => {
|
|
3598
|
+
try {
|
|
3599
|
+
const overrides = getOverrides6(cmd);
|
|
3600
|
+
const resolved = parseEntityReference(ref, overrides);
|
|
3601
|
+
const api = createApiClient();
|
|
3602
|
+
await api.storage.removeColumn(resolved, parseInt(index, 10));
|
|
3603
|
+
console.log(chalk15.green(`Column ${index} removed.`));
|
|
3604
|
+
} catch (error) {
|
|
3605
|
+
handleError(error);
|
|
3606
|
+
}
|
|
3607
|
+
});
|
|
3608
|
+
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) => {
|
|
3609
|
+
try {
|
|
3610
|
+
const overrides = getOverrides6(cmd);
|
|
2970
3611
|
const resolved = parseEntityReference(ref, overrides);
|
|
2971
3612
|
const api = createApiClient();
|
|
2972
3613
|
await api.storage.deleteColumn(resolved, parseInt(index, 10));
|
|
2973
|
-
console.log(
|
|
3614
|
+
console.log(chalk15.green(`Column ${index} deleted.`));
|
|
2974
3615
|
} catch (error) {
|
|
2975
3616
|
handleError(error);
|
|
2976
3617
|
}
|
|
@@ -2978,7 +3619,7 @@ function registerTableCommands(program) {
|
|
|
2978
3619
|
const cell = table.command("cell").description("Manage table cells");
|
|
2979
3620
|
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) => {
|
|
2980
3621
|
try {
|
|
2981
|
-
const overrides =
|
|
3622
|
+
const overrides = getOverrides6(cmd);
|
|
2982
3623
|
const resolved = parseEntityReference(ref, overrides);
|
|
2983
3624
|
const api = createApiClient();
|
|
2984
3625
|
await api.storage.mergeCells(resolved, [{
|
|
@@ -2987,29 +3628,142 @@ function registerTableCommands(program) {
|
|
|
2987
3628
|
value,
|
|
2988
3629
|
type: "text"
|
|
2989
3630
|
}]);
|
|
2990
|
-
console.log(
|
|
3631
|
+
console.log(chalk15.green(`Cell [${row2}, ${col}] set to "${value}".`));
|
|
2991
3632
|
} catch (error) {
|
|
2992
3633
|
handleError(error);
|
|
2993
3634
|
}
|
|
2994
3635
|
});
|
|
2995
3636
|
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) => {
|
|
2996
3637
|
try {
|
|
2997
|
-
const overrides =
|
|
3638
|
+
const overrides = getOverrides6(cmd);
|
|
2998
3639
|
const resolved = parseEntityReference(ref, overrides);
|
|
2999
3640
|
const api = createApiClient();
|
|
3000
|
-
await api.storage.
|
|
3001
|
-
console.log(
|
|
3641
|
+
await api.storage.removeCell(resolved, parseInt(row2, 10), parseInt(col, 10));
|
|
3642
|
+
console.log(chalk15.green(`Cell [${row2}, ${col}] deleted.`));
|
|
3002
3643
|
} catch (error) {
|
|
3003
3644
|
handleError(error);
|
|
3004
3645
|
}
|
|
3005
3646
|
});
|
|
3006
|
-
table.command("clear").description("Clear all data from a table").argument("<ref>", "Table entity reference").action(async (ref,
|
|
3647
|
+
table.command("clear").description("Clear all data from a table").argument("<ref>", "Table entity reference").option("-y, --yes", "Skip confirmation prompt (for CI / scripted use)").action(async (ref, options, cmd) => {
|
|
3007
3648
|
try {
|
|
3008
|
-
|
|
3649
|
+
await confirmDestructive(`This will permanently delete all data in table "${ref}".`, { yes: options.yes, resourceId: ref });
|
|
3650
|
+
const overrides = getOverrides6(cmd);
|
|
3009
3651
|
const resolved = parseEntityReference(ref, overrides);
|
|
3010
3652
|
const api = createApiClient();
|
|
3011
3653
|
await api.storage.clearTable(resolved);
|
|
3012
|
-
console.log(
|
|
3654
|
+
console.log(chalk15.green("Table cleared."));
|
|
3655
|
+
} catch (error) {
|
|
3656
|
+
handleError(error);
|
|
3657
|
+
}
|
|
3658
|
+
});
|
|
3659
|
+
}
|
|
3660
|
+
|
|
3661
|
+
// src/commands/notebook/index.ts
|
|
3662
|
+
import chalk16 from "chalk";
|
|
3663
|
+
import * as fs5 from "fs";
|
|
3664
|
+
import * as path4 from "path";
|
|
3665
|
+
function getOutputFormat7(cmd) {
|
|
3666
|
+
const config = loadConfig();
|
|
3667
|
+
const globalOpts = cmd.optsWithGlobals();
|
|
3668
|
+
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
3669
|
+
}
|
|
3670
|
+
function getOverrides7(cmd) {
|
|
3671
|
+
const opts = cmd.optsWithGlobals();
|
|
3672
|
+
return { project: opts.project, branch: opts.branch };
|
|
3673
|
+
}
|
|
3674
|
+
function registerNotebookCommands(program) {
|
|
3675
|
+
const notebook = program.command("notebook").description("Export and import notebook bundles");
|
|
3676
|
+
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) => {
|
|
3677
|
+
try {
|
|
3678
|
+
const overrides = getOverrides7(cmd);
|
|
3679
|
+
const ref = parseProjectReference(project, overrides);
|
|
3680
|
+
const api = createApiClient();
|
|
3681
|
+
const request = { rootEntityIds: notebookIds, dataFormat: options.data };
|
|
3682
|
+
if (options.async) {
|
|
3683
|
+
const bundleId = await api.storage.exportBundle(ref.projectId, ref.projectBranch, request);
|
|
3684
|
+
console.log(chalk16.green(`Export queued (bundle ID: ${bundleId}).`));
|
|
3685
|
+
console.log(`Poll progress: diafunc notebook bundles ${project}`);
|
|
3686
|
+
return;
|
|
3687
|
+
}
|
|
3688
|
+
const response = await api.storage.streamBundle(ref.projectId, ref.projectBranch, request);
|
|
3689
|
+
const outFile = options.out ?? "notebooks.dfnb";
|
|
3690
|
+
const buffer = Buffer.from(await response.arrayBuffer());
|
|
3691
|
+
fs5.writeFileSync(outFile, buffer);
|
|
3692
|
+
console.log(chalk16.green(`Bundle written to ${outFile} (${buffer.length} bytes, ${notebookIds.length} notebook(s)).`));
|
|
3693
|
+
} catch (error) {
|
|
3694
|
+
handleError(error);
|
|
3695
|
+
}
|
|
3696
|
+
});
|
|
3697
|
+
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) => {
|
|
3698
|
+
try {
|
|
3699
|
+
const outputFormat = getOutputFormat7(cmd);
|
|
3700
|
+
const overrides = getOverrides7(cmd);
|
|
3701
|
+
const ref = parseProjectReference(project, overrides);
|
|
3702
|
+
const api = createApiClient();
|
|
3703
|
+
const fileBuffer = fs5.readFileSync(file);
|
|
3704
|
+
const blob = new Blob([fileBuffer]);
|
|
3705
|
+
const formData = new FormData();
|
|
3706
|
+
formData.append("content", blob, path4.basename(file));
|
|
3707
|
+
if (options.preview) {
|
|
3708
|
+
const preview = await api.storage.previewBundleImport(ref.projectId, ref.projectBranch, formData);
|
|
3709
|
+
if (outputFormat === "json") {
|
|
3710
|
+
format(preview, { format: outputFormat });
|
|
3711
|
+
return;
|
|
3712
|
+
}
|
|
3713
|
+
console.log(chalk16.bold(`${preview.kind} bundle \xB7 ${preview.entityCount} entities`));
|
|
3714
|
+
if (preview.sourceProjectId) {
|
|
3715
|
+
console.log(chalk16.dim(`from ${preview.sourceProjectId}/${preview.sourceProjectBranch}` + (preview.createdBy ? ` \xB7 by ${preview.createdBy}` : "")));
|
|
3716
|
+
}
|
|
3717
|
+
const counts = /* @__PURE__ */ new Map();
|
|
3718
|
+
for (const e of preview.entities ?? []) {
|
|
3719
|
+
counts.set(e.type, (counts.get(e.type) ?? 0) + 1);
|
|
3720
|
+
}
|
|
3721
|
+
for (const [type, count] of [...counts.entries()].sort((a, b) => a[0].localeCompare(b[0]))) {
|
|
3722
|
+
console.log(` ${type}: ${count}`);
|
|
3723
|
+
}
|
|
3724
|
+
if (preview.lossinessNotes && preview.lossinessNotes.length > 0) {
|
|
3725
|
+
console.log(chalk16.yellow("Lossiness:"));
|
|
3726
|
+
for (const note of preview.lossinessNotes) {
|
|
3727
|
+
console.log(chalk16.yellow(` - ${note}`));
|
|
3728
|
+
}
|
|
3729
|
+
}
|
|
3730
|
+
return;
|
|
3731
|
+
}
|
|
3732
|
+
const result = await api.storage.importBundle(ref.projectId, ref.projectBranch, formData, options.onConflict);
|
|
3733
|
+
if (outputFormat === "json") {
|
|
3734
|
+
format(result, { format: outputFormat });
|
|
3735
|
+
return;
|
|
3736
|
+
}
|
|
3737
|
+
console.log(chalk16.green(`Imported ${result.entityCount} entities, ${result.linkCount} links.`));
|
|
3738
|
+
console.log(`Notebook id(s): ${result.rootEntityIds.join(", ")}`);
|
|
3739
|
+
} catch (error) {
|
|
3740
|
+
handleError(error);
|
|
3741
|
+
}
|
|
3742
|
+
});
|
|
3743
|
+
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) => {
|
|
3744
|
+
try {
|
|
3745
|
+
const outputFormat = getOutputFormat7(cmd);
|
|
3746
|
+
const overrides = getOverrides7(cmd);
|
|
3747
|
+
const ref = parseProjectReference(project, overrides);
|
|
3748
|
+
const api = createApiClient();
|
|
3749
|
+
const bundles = await api.storage.getBundles(ref.projectId, ref.projectBranch);
|
|
3750
|
+
if (outputFormat === "json") {
|
|
3751
|
+
format(bundles, { format: outputFormat });
|
|
3752
|
+
return;
|
|
3753
|
+
}
|
|
3754
|
+
const rows = bundles.map((b) => ({
|
|
3755
|
+
bundleId: b.bundleId,
|
|
3756
|
+
kind: b.kind,
|
|
3757
|
+
filename: b.filename,
|
|
3758
|
+
entities: b.entityCount ?? "",
|
|
3759
|
+
progress: b.progress,
|
|
3760
|
+
succeeded: b.succeeded ?? "",
|
|
3761
|
+
error: b.error ?? ""
|
|
3762
|
+
}));
|
|
3763
|
+
format(rows, {
|
|
3764
|
+
format: outputFormat,
|
|
3765
|
+
columns: ["bundleId", "kind", "filename", "entities", "progress", "succeeded", "error"]
|
|
3766
|
+
});
|
|
3013
3767
|
} catch (error) {
|
|
3014
3768
|
handleError(error);
|
|
3015
3769
|
}
|
|
@@ -3017,10 +3771,10 @@ function registerTableCommands(program) {
|
|
|
3017
3771
|
}
|
|
3018
3772
|
|
|
3019
3773
|
// src/commands/function/index.ts
|
|
3020
|
-
import
|
|
3021
|
-
import * as
|
|
3774
|
+
import chalk17 from "chalk";
|
|
3775
|
+
import * as fs6 from "fs";
|
|
3022
3776
|
import * as os2 from "os";
|
|
3023
|
-
import * as
|
|
3777
|
+
import * as path5 from "path";
|
|
3024
3778
|
import { spawn } from "child_process";
|
|
3025
3779
|
import { randomUUID } from "crypto";
|
|
3026
3780
|
|
|
@@ -3073,12 +3827,12 @@ function buildFunctionEntity(args) {
|
|
|
3073
3827
|
}
|
|
3074
3828
|
|
|
3075
3829
|
// src/commands/function/index.ts
|
|
3076
|
-
function
|
|
3830
|
+
function getOutputFormat8(cmd) {
|
|
3077
3831
|
const config = loadConfig();
|
|
3078
3832
|
const globalOpts = cmd.optsWithGlobals();
|
|
3079
3833
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
3080
3834
|
}
|
|
3081
|
-
function
|
|
3835
|
+
function getOverrides8(cmd) {
|
|
3082
3836
|
const opts = cmd.optsWithGlobals();
|
|
3083
3837
|
return { project: opts.project, branch: opts.branch };
|
|
3084
3838
|
}
|
|
@@ -3096,8 +3850,8 @@ function registerFunctionCommands(program) {
|
|
|
3096
3850
|
const fn = program.command("function").description("Execute and manage functions");
|
|
3097
3851
|
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) => {
|
|
3098
3852
|
try {
|
|
3099
|
-
const outputFormat =
|
|
3100
|
-
const overrides =
|
|
3853
|
+
const outputFormat = getOutputFormat8(cmd);
|
|
3854
|
+
const overrides = getOverrides8(cmd);
|
|
3101
3855
|
const resolved = parseEntityReference(ref, overrides);
|
|
3102
3856
|
const api = createApiClient();
|
|
3103
3857
|
const time = createTimeUuid();
|
|
@@ -3139,7 +3893,7 @@ function registerFunctionCommands(program) {
|
|
|
3139
3893
|
}, isAsync);
|
|
3140
3894
|
if (isAsync) {
|
|
3141
3895
|
if (outputFormat === "human") {
|
|
3142
|
-
console.log(
|
|
3896
|
+
console.log(chalk17.green("Function launched."));
|
|
3143
3897
|
console.log(` Evaluation ID: ${result.evaluationId}`);
|
|
3144
3898
|
} else {
|
|
3145
3899
|
format({ evaluationId: result.evaluationId }, { format: outputFormat });
|
|
@@ -3147,14 +3901,14 @@ function registerFunctionCommands(program) {
|
|
|
3147
3901
|
} else {
|
|
3148
3902
|
if (outputFormat === "human") {
|
|
3149
3903
|
if (result.successful) {
|
|
3150
|
-
console.log(
|
|
3904
|
+
console.log(chalk17.green("Function completed successfully."));
|
|
3151
3905
|
if (result.result) {
|
|
3152
3906
|
console.log(` Result: ${result.result}`);
|
|
3153
3907
|
}
|
|
3154
3908
|
const duration = result.completed - result.started;
|
|
3155
3909
|
console.log(` Duration: ${duration}ms`);
|
|
3156
3910
|
} else {
|
|
3157
|
-
console.log(
|
|
3911
|
+
console.log(chalk17.red("Function failed."));
|
|
3158
3912
|
console.log(` Error: ${result.error}`);
|
|
3159
3913
|
if (result.lineNumber > 0) {
|
|
3160
3914
|
console.log(` Line: ${result.lineNumber}, Column: ${result.columnNumber}`);
|
|
@@ -3162,7 +3916,7 @@ function registerFunctionCommands(program) {
|
|
|
3162
3916
|
}
|
|
3163
3917
|
if (result.outputs?.length) {
|
|
3164
3918
|
console.log();
|
|
3165
|
-
console.log(
|
|
3919
|
+
console.log(chalk17.bold("Outputs:"));
|
|
3166
3920
|
for (const out of result.outputs) {
|
|
3167
3921
|
console.log(` [${out.type}] ${out.output}`);
|
|
3168
3922
|
}
|
|
@@ -3177,8 +3931,8 @@ function registerFunctionCommands(program) {
|
|
|
3177
3931
|
});
|
|
3178
3932
|
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) => {
|
|
3179
3933
|
try {
|
|
3180
|
-
const outputFormat =
|
|
3181
|
-
const overrides =
|
|
3934
|
+
const outputFormat = getOutputFormat8(cmd);
|
|
3935
|
+
const overrides = getOverrides8(cmd);
|
|
3182
3936
|
const resolved = parseEntityReference(ref, overrides);
|
|
3183
3937
|
const api = createApiClient();
|
|
3184
3938
|
const parts = options.date.split("-").map(Number);
|
|
@@ -3211,16 +3965,16 @@ function registerFunctionCommands(program) {
|
|
|
3211
3965
|
});
|
|
3212
3966
|
fn.command("outputs").description("Get outputs for an evaluation").argument("<projectId>", "Project ID").argument("<evaluationId>", "Evaluation ID").action(async (projectId, evaluationId, _options, cmd) => {
|
|
3213
3967
|
try {
|
|
3214
|
-
const outputFormat =
|
|
3968
|
+
const outputFormat = getOutputFormat8(cmd);
|
|
3215
3969
|
const api = createApiClient();
|
|
3216
3970
|
const outputs = await api.evaluation.getOutputs(projectId, evaluationId);
|
|
3217
3971
|
if (outputFormat === "human") {
|
|
3218
3972
|
if (outputs.length === 0) {
|
|
3219
|
-
console.log(
|
|
3973
|
+
console.log(chalk17.dim("No outputs."));
|
|
3220
3974
|
}
|
|
3221
3975
|
for (const out of outputs) {
|
|
3222
3976
|
const time = new Date(out.timestamp).toISOString();
|
|
3223
|
-
console.log(`${
|
|
3977
|
+
console.log(`${chalk17.dim(time)} [${out.type}] ${out.output}`);
|
|
3224
3978
|
}
|
|
3225
3979
|
} else {
|
|
3226
3980
|
format(outputs, { format: outputFormat });
|
|
@@ -3231,8 +3985,8 @@ function registerFunctionCommands(program) {
|
|
|
3231
3985
|
});
|
|
3232
3986
|
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) => {
|
|
3233
3987
|
try {
|
|
3234
|
-
const outputFormat =
|
|
3235
|
-
const overrides =
|
|
3988
|
+
const outputFormat = getOutputFormat8(cmd);
|
|
3989
|
+
const overrides = getOverrides8(cmd);
|
|
3236
3990
|
const resolved = parseEntityReference(ref, overrides);
|
|
3237
3991
|
const api = createApiClient();
|
|
3238
3992
|
const parts = options.date.split("-").map(Number);
|
|
@@ -3254,7 +4008,7 @@ function registerFunctionCommands(program) {
|
|
|
3254
4008
|
});
|
|
3255
4009
|
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) => {
|
|
3256
4010
|
try {
|
|
3257
|
-
const overrides =
|
|
4011
|
+
const overrides = getOverrides8(cmd);
|
|
3258
4012
|
const resolved = parseEntityReference(ref, overrides);
|
|
3259
4013
|
const api = createApiClient();
|
|
3260
4014
|
const parts = options.date.split("-").map(Number);
|
|
@@ -3270,14 +4024,14 @@ function registerFunctionCommands(program) {
|
|
|
3270
4024
|
hour,
|
|
3271
4025
|
evaluationId
|
|
3272
4026
|
);
|
|
3273
|
-
console.log(
|
|
4027
|
+
console.log(chalk17.green(`Evaluation ${evaluationId} stopped.`));
|
|
3274
4028
|
} catch (error) {
|
|
3275
4029
|
handleError(error);
|
|
3276
4030
|
}
|
|
3277
4031
|
});
|
|
3278
4032
|
fn.command("engines").description("List available engines").action(async (_options, cmd) => {
|
|
3279
4033
|
try {
|
|
3280
|
-
const outputFormat =
|
|
4034
|
+
const outputFormat = getOutputFormat8(cmd);
|
|
3281
4035
|
const api = createApiClient();
|
|
3282
4036
|
const engines = await api.evaluation.getEngines();
|
|
3283
4037
|
format(engines, { format: outputFormat });
|
|
@@ -3287,8 +4041,8 @@ function registerFunctionCommands(program) {
|
|
|
3287
4041
|
});
|
|
3288
4042
|
fn.command("last-evaluation").description("Show the most recent evaluation of a function").argument("<ref>", "Function entity reference").action(async (ref, _options, cmd) => {
|
|
3289
4043
|
try {
|
|
3290
|
-
const outputFormat =
|
|
3291
|
-
const overrides =
|
|
4044
|
+
const outputFormat = getOutputFormat8(cmd);
|
|
4045
|
+
const overrides = getOverrides8(cmd);
|
|
3292
4046
|
const resolved = parseEntityReference(ref, overrides);
|
|
3293
4047
|
const api = createApiClient();
|
|
3294
4048
|
const evaluation = await api.evaluation.getLastEvaluation(
|
|
@@ -3304,10 +4058,10 @@ function registerFunctionCommands(program) {
|
|
|
3304
4058
|
});
|
|
3305
4059
|
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) => {
|
|
3306
4060
|
try {
|
|
3307
|
-
const overrides =
|
|
4061
|
+
const overrides = getOverrides8(cmd);
|
|
3308
4062
|
const resolved = parseEntityReference(ref, overrides);
|
|
3309
4063
|
const api = createApiClient();
|
|
3310
|
-
const sourceCode = options.source ?
|
|
4064
|
+
const sourceCode = options.source ? fs6.readFileSync(options.source, "utf-8") : "";
|
|
3311
4065
|
const entity = buildFunctionEntity({
|
|
3312
4066
|
projectId: resolved.projectId,
|
|
3313
4067
|
projectBranch: resolved.projectBranch,
|
|
@@ -3318,7 +4072,7 @@ function registerFunctionCommands(program) {
|
|
|
3318
4072
|
sourceCode
|
|
3319
4073
|
});
|
|
3320
4074
|
await api.storage.saveEntities([entity]);
|
|
3321
|
-
console.log(
|
|
4075
|
+
console.log(chalk17.green(`Function "${resolved.entityId}" created (${options.language}).`));
|
|
3322
4076
|
} catch (error) {
|
|
3323
4077
|
handleError(error);
|
|
3324
4078
|
}
|
|
@@ -3326,14 +4080,14 @@ function registerFunctionCommands(program) {
|
|
|
3326
4080
|
const source = fn.command("source").description("Get or set function source code");
|
|
3327
4081
|
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) => {
|
|
3328
4082
|
try {
|
|
3329
|
-
const overrides =
|
|
4083
|
+
const overrides = getOverrides8(cmd);
|
|
3330
4084
|
const resolved = parseEntityReference(ref, overrides);
|
|
3331
4085
|
const api = createApiClient();
|
|
3332
4086
|
const entity = await api.storage.getEntity(resolved, true);
|
|
3333
4087
|
const sourceCode = decodeFunctionSource(entity);
|
|
3334
4088
|
if (options.out) {
|
|
3335
|
-
|
|
3336
|
-
console.log(
|
|
4089
|
+
fs6.writeFileSync(options.out, sourceCode);
|
|
4090
|
+
console.log(chalk17.green(`Source written to ${options.out}`));
|
|
3337
4091
|
} else {
|
|
3338
4092
|
process.stdout.write(sourceCode);
|
|
3339
4093
|
if (!sourceCode.endsWith("\n")) process.stdout.write("\n");
|
|
@@ -3344,10 +4098,10 @@ function registerFunctionCommands(program) {
|
|
|
3344
4098
|
});
|
|
3345
4099
|
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) => {
|
|
3346
4100
|
try {
|
|
3347
|
-
const overrides =
|
|
4101
|
+
const overrides = getOverrides8(cmd);
|
|
3348
4102
|
const resolved = parseEntityReference(ref, overrides);
|
|
3349
4103
|
const api = createApiClient();
|
|
3350
|
-
const sourceCode = file ?
|
|
4104
|
+
const sourceCode = file ? fs6.readFileSync(file, "utf-8") : await new Promise((resolve, reject) => {
|
|
3351
4105
|
let data = "";
|
|
3352
4106
|
process.stdin.setEncoding("utf-8");
|
|
3353
4107
|
process.stdin.on("data", (chunk) => {
|
|
@@ -3357,36 +4111,36 @@ function registerFunctionCommands(program) {
|
|
|
3357
4111
|
process.stdin.on("error", reject);
|
|
3358
4112
|
});
|
|
3359
4113
|
await api.storage.saveEntityContentBase64(resolved, encodeFunctionSource(sourceCode));
|
|
3360
|
-
console.log(
|
|
4114
|
+
console.log(chalk17.green(`Source updated for "${resolved.entityId}".`));
|
|
3361
4115
|
} catch (error) {
|
|
3362
4116
|
handleError(error);
|
|
3363
4117
|
}
|
|
3364
4118
|
});
|
|
3365
4119
|
fn.command("edit").description("Open the function source in $EDITOR and save on exit").argument("<ref>", "Function entity reference").action(async (ref, _options, cmd) => {
|
|
3366
4120
|
try {
|
|
3367
|
-
const overrides =
|
|
4121
|
+
const overrides = getOverrides8(cmd);
|
|
3368
4122
|
const resolved = parseEntityReference(ref, overrides);
|
|
3369
4123
|
const api = createApiClient();
|
|
3370
4124
|
const entity = await api.storage.getEntity(resolved, true);
|
|
3371
4125
|
const currentSource = decodeFunctionSource(entity);
|
|
3372
4126
|
const language = entity.attributes?.["language"] ?? "txt";
|
|
3373
4127
|
const ext = extensionFor(language);
|
|
3374
|
-
const tmpFile =
|
|
3375
|
-
|
|
4128
|
+
const tmpFile = path5.join(os2.tmpdir(), `diafunc-${resolved.entityId}-${randomUUID()}.${ext}`);
|
|
4129
|
+
fs6.writeFileSync(tmpFile, currentSource);
|
|
3376
4130
|
const editor = process.env.VISUAL ?? process.env.EDITOR ?? "vi";
|
|
3377
4131
|
await new Promise((resolve, reject) => {
|
|
3378
4132
|
const child = spawn(editor, [tmpFile], { stdio: "inherit" });
|
|
3379
4133
|
child.on("exit", (code) => code === 0 ? resolve() : reject(new Error(`Editor exited with code ${code}`)));
|
|
3380
4134
|
child.on("error", reject);
|
|
3381
4135
|
});
|
|
3382
|
-
const newSource =
|
|
3383
|
-
|
|
4136
|
+
const newSource = fs6.readFileSync(tmpFile, "utf-8");
|
|
4137
|
+
fs6.unlinkSync(tmpFile);
|
|
3384
4138
|
if (newSource === currentSource) {
|
|
3385
|
-
console.log(
|
|
4139
|
+
console.log(chalk17.dim("No changes."));
|
|
3386
4140
|
return;
|
|
3387
4141
|
}
|
|
3388
4142
|
await api.storage.saveEntityContentBase64(resolved, encodeFunctionSource(newSource));
|
|
3389
|
-
console.log(
|
|
4143
|
+
console.log(chalk17.green(`Source updated for "${resolved.entityId}".`));
|
|
3390
4144
|
} catch (error) {
|
|
3391
4145
|
handleError(error);
|
|
3392
4146
|
}
|
|
@@ -3403,13 +4157,13 @@ function extensionFor(language) {
|
|
|
3403
4157
|
}
|
|
3404
4158
|
|
|
3405
4159
|
// src/commands/trigger/index.ts
|
|
3406
|
-
import
|
|
3407
|
-
function
|
|
4160
|
+
import chalk18 from "chalk";
|
|
4161
|
+
function getOutputFormat9(cmd) {
|
|
3408
4162
|
const config = loadConfig();
|
|
3409
4163
|
const globalOpts = cmd.optsWithGlobals();
|
|
3410
4164
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
3411
4165
|
}
|
|
3412
|
-
function
|
|
4166
|
+
function getOverrides9(cmd) {
|
|
3413
4167
|
const opts = cmd.optsWithGlobals();
|
|
3414
4168
|
return { project: opts.project, branch: opts.branch };
|
|
3415
4169
|
}
|
|
@@ -3417,8 +4171,8 @@ function registerTriggerCommands(program) {
|
|
|
3417
4171
|
const trigger = program.command("trigger").description("Manage function triggers");
|
|
3418
4172
|
trigger.command("list").description("List triggers for a function").argument("<ref>", "Function entity reference").action(async (ref, _options, cmd) => {
|
|
3419
4173
|
try {
|
|
3420
|
-
const outputFormat =
|
|
3421
|
-
const overrides =
|
|
4174
|
+
const outputFormat = getOutputFormat9(cmd);
|
|
4175
|
+
const overrides = getOverrides9(cmd);
|
|
3422
4176
|
const resolved = parseEntityReference(ref, overrides);
|
|
3423
4177
|
const api = createApiClient();
|
|
3424
4178
|
const triggers = await api.evaluation.getTriggers(
|
|
@@ -3445,8 +4199,8 @@ function registerTriggerCommands(program) {
|
|
|
3445
4199
|
});
|
|
3446
4200
|
trigger.command("get").description("Get a specific trigger").argument("<ref>", "Function entity reference").argument("<triggerId>", "Trigger ID").action(async (ref, triggerId, _options, cmd) => {
|
|
3447
4201
|
try {
|
|
3448
|
-
const outputFormat =
|
|
3449
|
-
const overrides =
|
|
4202
|
+
const outputFormat = getOutputFormat9(cmd);
|
|
4203
|
+
const overrides = getOverrides9(cmd);
|
|
3450
4204
|
const resolved = parseEntityReference(ref, overrides);
|
|
3451
4205
|
const api = createApiClient();
|
|
3452
4206
|
const t = await api.evaluation.getTrigger(
|
|
@@ -3463,7 +4217,7 @@ function registerTriggerCommands(program) {
|
|
|
3463
4217
|
});
|
|
3464
4218
|
trigger.command("delete").description("Delete a trigger").argument("<ref>", "Function entity reference").argument("<triggerId>", "Trigger ID").action(async (ref, triggerId, _options, cmd) => {
|
|
3465
4219
|
try {
|
|
3466
|
-
const overrides =
|
|
4220
|
+
const overrides = getOverrides9(cmd);
|
|
3467
4221
|
const resolved = parseEntityReference(ref, overrides);
|
|
3468
4222
|
const api = createApiClient();
|
|
3469
4223
|
await api.evaluation.deleteTrigger(
|
|
@@ -3473,14 +4227,14 @@ function registerTriggerCommands(program) {
|
|
|
3473
4227
|
resolved.entityBranch,
|
|
3474
4228
|
triggerId
|
|
3475
4229
|
);
|
|
3476
|
-
console.log(
|
|
4230
|
+
console.log(chalk18.green(`Trigger "${triggerId}" deleted.`));
|
|
3477
4231
|
} catch (error) {
|
|
3478
4232
|
handleError(error);
|
|
3479
4233
|
}
|
|
3480
4234
|
});
|
|
3481
4235
|
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) => {
|
|
3482
4236
|
try {
|
|
3483
|
-
const overrides =
|
|
4237
|
+
const overrides = getOverrides9(cmd);
|
|
3484
4238
|
const fn = parseEntityReference(ref, overrides);
|
|
3485
4239
|
const api = createApiClient();
|
|
3486
4240
|
const args = options.args ? JSON.parse(options.args) : null;
|
|
@@ -3521,7 +4275,7 @@ function registerTriggerCommands(program) {
|
|
|
3521
4275
|
scheduler: null,
|
|
3522
4276
|
heartbeat: null
|
|
3523
4277
|
});
|
|
3524
|
-
console.log(
|
|
4278
|
+
console.log(chalk18.green("Trigger saved."));
|
|
3525
4279
|
} catch (error) {
|
|
3526
4280
|
handleError(error);
|
|
3527
4281
|
}
|
|
@@ -3529,14 +4283,14 @@ function registerTriggerCommands(program) {
|
|
|
3529
4283
|
}
|
|
3530
4284
|
|
|
3531
4285
|
// src/commands/schedule/index.ts
|
|
3532
|
-
import
|
|
4286
|
+
import chalk19 from "chalk";
|
|
3533
4287
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
3534
|
-
function
|
|
4288
|
+
function getOutputFormat10(cmd) {
|
|
3535
4289
|
const config = loadConfig();
|
|
3536
4290
|
const globalOpts = cmd.optsWithGlobals();
|
|
3537
4291
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
3538
4292
|
}
|
|
3539
|
-
function
|
|
4293
|
+
function getOverrides10(cmd) {
|
|
3540
4294
|
const opts = cmd.optsWithGlobals();
|
|
3541
4295
|
return { project: opts.project, branch: opts.branch };
|
|
3542
4296
|
}
|
|
@@ -3544,8 +4298,8 @@ function registerScheduleCommands(program) {
|
|
|
3544
4298
|
const schedule = program.command("schedule").description("Schedule function execution");
|
|
3545
4299
|
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) => {
|
|
3546
4300
|
try {
|
|
3547
|
-
const outputFormat =
|
|
3548
|
-
const overrides =
|
|
4301
|
+
const outputFormat = getOutputFormat10(cmd);
|
|
4302
|
+
const overrides = getOverrides10(cmd);
|
|
3549
4303
|
const resolved = parseEntityReference(ref, overrides);
|
|
3550
4304
|
const api = createApiClient();
|
|
3551
4305
|
let args = null;
|
|
@@ -3581,7 +4335,7 @@ function registerScheduleCommands(program) {
|
|
|
3581
4335
|
removeFunction: false
|
|
3582
4336
|
});
|
|
3583
4337
|
if (outputFormat === "human") {
|
|
3584
|
-
console.log(
|
|
4338
|
+
console.log(chalk19.green("Function scheduled."));
|
|
3585
4339
|
} else {
|
|
3586
4340
|
format(result, { format: outputFormat });
|
|
3587
4341
|
}
|
|
@@ -3591,7 +4345,7 @@ function registerScheduleCommands(program) {
|
|
|
3591
4345
|
});
|
|
3592
4346
|
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) => {
|
|
3593
4347
|
try {
|
|
3594
|
-
const overrides =
|
|
4348
|
+
const overrides = getOverrides10(cmd);
|
|
3595
4349
|
const resolved = parseEntityReference(ref, overrides);
|
|
3596
4350
|
const api = createApiClient();
|
|
3597
4351
|
const [year, month, day, hour] = options.date.split("-").map(Number);
|
|
@@ -3606,15 +4360,15 @@ function registerScheduleCommands(program) {
|
|
|
3606
4360
|
hour,
|
|
3607
4361
|
evaluationId
|
|
3608
4362
|
);
|
|
3609
|
-
console.log(
|
|
4363
|
+
console.log(chalk19.green(`Scheduled evaluation ${evaluationId} stopped.`));
|
|
3610
4364
|
} catch (error) {
|
|
3611
4365
|
handleError(error);
|
|
3612
4366
|
}
|
|
3613
4367
|
});
|
|
3614
4368
|
schedule.command("list").description("List persistent triggers (scheduled functions are modeled as triggers)").argument("<ref>", "Function entity reference").action(async (ref, _options, cmd) => {
|
|
3615
4369
|
try {
|
|
3616
|
-
const outputFormat =
|
|
3617
|
-
const overrides =
|
|
4370
|
+
const outputFormat = getOutputFormat10(cmd);
|
|
4371
|
+
const overrides = getOverrides10(cmd);
|
|
3618
4372
|
const resolved = parseEntityReference(ref, overrides);
|
|
3619
4373
|
const api = createApiClient();
|
|
3620
4374
|
const triggers = await api.evaluation.getTriggers(
|
|
@@ -3643,10 +4397,10 @@ function registerScheduleCommands(program) {
|
|
|
3643
4397
|
}
|
|
3644
4398
|
|
|
3645
4399
|
// src/commands/chat/index.ts
|
|
3646
|
-
import
|
|
3647
|
-
import * as
|
|
3648
|
-
import * as
|
|
3649
|
-
function
|
|
4400
|
+
import chalk20 from "chalk";
|
|
4401
|
+
import * as fs7 from "fs";
|
|
4402
|
+
import * as path6 from "path";
|
|
4403
|
+
function getOutputFormat11(cmd) {
|
|
3650
4404
|
const config = loadConfig();
|
|
3651
4405
|
const globalOpts = cmd.optsWithGlobals();
|
|
3652
4406
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -3684,7 +4438,7 @@ async function streamOneTurn(message, sessionId, projectId, branch) {
|
|
|
3684
4438
|
input = event.inputTokens;
|
|
3685
4439
|
output = event.outputTokens;
|
|
3686
4440
|
} else if (event.type === "error") {
|
|
3687
|
-
console.error(
|
|
4441
|
+
console.error(chalk20.red(`
|
|
3688
4442
|
Error: ${event.content}`));
|
|
3689
4443
|
}
|
|
3690
4444
|
} catch {
|
|
@@ -3695,19 +4449,19 @@ Error: ${event.content}`));
|
|
|
3695
4449
|
}
|
|
3696
4450
|
async function runChatRepl(options) {
|
|
3697
4451
|
const { input: promptInput } = await import("@inquirer/prompts");
|
|
3698
|
-
const { getUpdateNotice } = await import("./update-check-
|
|
4452
|
+
const { getUpdateNotice } = await import("./update-check-2X2AIL52.js");
|
|
3699
4453
|
let sessionId = options.session;
|
|
3700
|
-
console.log(
|
|
4454
|
+
console.log(chalk20.bold("Diafunc chat") + chalk20.dim(" \xB7 /help for commands, /quit to exit"));
|
|
3701
4455
|
if (sessionId) {
|
|
3702
|
-
console.log(
|
|
4456
|
+
console.log(chalk20.dim(`Continuing session ${sessionId}`));
|
|
3703
4457
|
}
|
|
3704
4458
|
const notice = await getUpdateNotice();
|
|
3705
|
-
if (notice) console.log(
|
|
4459
|
+
if (notice) console.log(chalk20.dim(notice));
|
|
3706
4460
|
console.log();
|
|
3707
4461
|
for (; ; ) {
|
|
3708
4462
|
let line;
|
|
3709
4463
|
try {
|
|
3710
|
-
line = await promptInput({ message:
|
|
4464
|
+
line = await promptInput({ message: chalk20.cyan.bold("you >") });
|
|
3711
4465
|
} catch {
|
|
3712
4466
|
console.log();
|
|
3713
4467
|
return;
|
|
@@ -3724,37 +4478,37 @@ async function runChatRepl(options) {
|
|
|
3724
4478
|
return;
|
|
3725
4479
|
case "new":
|
|
3726
4480
|
sessionId = void 0;
|
|
3727
|
-
console.log(
|
|
4481
|
+
console.log(chalk20.dim("Started a new session."));
|
|
3728
4482
|
continue;
|
|
3729
4483
|
case "session":
|
|
3730
4484
|
if (!arg) {
|
|
3731
|
-
console.log(
|
|
4485
|
+
console.log(chalk20.dim(`Current session: ${sessionId ?? "(new)"}`));
|
|
3732
4486
|
} else {
|
|
3733
4487
|
sessionId = arg;
|
|
3734
|
-
console.log(
|
|
4488
|
+
console.log(chalk20.dim(`Switched to session ${sessionId}`));
|
|
3735
4489
|
}
|
|
3736
4490
|
continue;
|
|
3737
4491
|
case "help":
|
|
3738
4492
|
case "h":
|
|
3739
4493
|
case "?":
|
|
3740
|
-
console.log(
|
|
3741
|
-
console.log(
|
|
3742
|
-
console.log(
|
|
4494
|
+
console.log(chalk20.dim(" /new start a new session"));
|
|
4495
|
+
console.log(chalk20.dim(" /session [id] switch to a session (no id = show current)"));
|
|
4496
|
+
console.log(chalk20.dim(" /quit exit the REPL"));
|
|
3743
4497
|
continue;
|
|
3744
4498
|
default:
|
|
3745
|
-
console.log(
|
|
4499
|
+
console.log(chalk20.dim(`Unknown command: /${cmd}. Try /help.`));
|
|
3746
4500
|
continue;
|
|
3747
4501
|
}
|
|
3748
4502
|
}
|
|
3749
|
-
process.stdout.write(
|
|
4503
|
+
process.stdout.write(chalk20.magenta.bold("diafunc > "));
|
|
3750
4504
|
try {
|
|
3751
4505
|
const result = await streamOneTurn(trimmed, sessionId, options.project, options.branch);
|
|
3752
4506
|
sessionId = result.sessionId || sessionId;
|
|
3753
4507
|
console.log();
|
|
3754
|
-
console.log(
|
|
4508
|
+
console.log(chalk20.dim(`[session ${sessionId} \xB7 ${result.input} in / ${result.output} out]`));
|
|
3755
4509
|
console.log();
|
|
3756
4510
|
} catch (error) {
|
|
3757
|
-
console.error(
|
|
4511
|
+
console.error(chalk20.red(`
|
|
3758
4512
|
Request failed: ${error.message}`));
|
|
3759
4513
|
}
|
|
3760
4514
|
}
|
|
@@ -3770,7 +4524,7 @@ function registerChatCommands(program) {
|
|
|
3770
4524
|
});
|
|
3771
4525
|
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) => {
|
|
3772
4526
|
try {
|
|
3773
|
-
const outputFormat =
|
|
4527
|
+
const outputFormat = getOutputFormat11(cmd);
|
|
3774
4528
|
const api = createApiClient();
|
|
3775
4529
|
const response = await api.language.chat({
|
|
3776
4530
|
message,
|
|
@@ -3781,7 +4535,7 @@ function registerChatCommands(program) {
|
|
|
3781
4535
|
if (outputFormat === "human") {
|
|
3782
4536
|
console.log(response.content);
|
|
3783
4537
|
console.log();
|
|
3784
|
-
console.log(
|
|
4538
|
+
console.log(chalk20.dim(`Session: ${response.sessionId} | Tokens: ${response.inputTokens} in, ${response.outputTokens} out`));
|
|
3785
4539
|
} else {
|
|
3786
4540
|
format(response, { format: outputFormat });
|
|
3787
4541
|
}
|
|
@@ -3791,7 +4545,7 @@ function registerChatCommands(program) {
|
|
|
3791
4545
|
});
|
|
3792
4546
|
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) => {
|
|
3793
4547
|
try {
|
|
3794
|
-
const outputFormat =
|
|
4548
|
+
const outputFormat = getOutputFormat11(cmd);
|
|
3795
4549
|
const api = createApiClient();
|
|
3796
4550
|
const response = await api.language.chatStream({
|
|
3797
4551
|
message,
|
|
@@ -3846,9 +4600,9 @@ function registerChatCommands(program) {
|
|
|
3846
4600
|
sessionId = event.sessionId ?? "";
|
|
3847
4601
|
console.log();
|
|
3848
4602
|
console.log();
|
|
3849
|
-
console.log(
|
|
4603
|
+
console.log(chalk20.dim(`Session: ${sessionId} | Tokens: ${event.inputTokens} in, ${event.outputTokens} out`));
|
|
3850
4604
|
} else if (event.type === "error") {
|
|
3851
|
-
console.error(
|
|
4605
|
+
console.error(chalk20.red(`
|
|
3852
4606
|
Error: ${event.content}`));
|
|
3853
4607
|
}
|
|
3854
4608
|
} catch {
|
|
@@ -3863,17 +4617,17 @@ Error: ${event.content}`));
|
|
|
3863
4617
|
});
|
|
3864
4618
|
chat.command("upload").description("Upload a file for chat context").argument("<file>", "File to upload").action(async (file) => {
|
|
3865
4619
|
try {
|
|
3866
|
-
if (!
|
|
3867
|
-
console.error(
|
|
4620
|
+
if (!fs7.existsSync(file)) {
|
|
4621
|
+
console.error(chalk20.red(`File not found: ${file}`));
|
|
3868
4622
|
process.exit(1);
|
|
3869
4623
|
}
|
|
3870
4624
|
const api = createApiClient();
|
|
3871
|
-
const fileBuffer =
|
|
4625
|
+
const fileBuffer = fs7.readFileSync(file);
|
|
3872
4626
|
const blob = new Blob([fileBuffer]);
|
|
3873
4627
|
const formData = new FormData();
|
|
3874
|
-
formData.append("file", blob,
|
|
4628
|
+
formData.append("file", blob, path6.basename(file));
|
|
3875
4629
|
const result = await api.language.upload(formData);
|
|
3876
|
-
console.log(
|
|
4630
|
+
console.log(chalk20.green(`File uploaded: ${result}`));
|
|
3877
4631
|
} catch (error) {
|
|
3878
4632
|
handleError(error);
|
|
3879
4633
|
}
|
|
@@ -3881,7 +4635,7 @@ Error: ${event.content}`));
|
|
|
3881
4635
|
const session = chat.command("session").description("Manage chat sessions");
|
|
3882
4636
|
session.command("list").description("List chat sessions").action(async (_options, cmd) => {
|
|
3883
4637
|
try {
|
|
3884
|
-
const outputFormat =
|
|
4638
|
+
const outputFormat = getOutputFormat11(cmd);
|
|
3885
4639
|
const api = createApiClient();
|
|
3886
4640
|
const sessions = await api.language.getSessions();
|
|
3887
4641
|
format(sessions, {
|
|
@@ -3896,22 +4650,22 @@ Error: ${event.content}`));
|
|
|
3896
4650
|
try {
|
|
3897
4651
|
const api = createApiClient();
|
|
3898
4652
|
await api.language.deleteSession(sessionId);
|
|
3899
|
-
console.log(
|
|
4653
|
+
console.log(chalk20.green(`Session "${sessionId}" deleted.`));
|
|
3900
4654
|
} catch (error) {
|
|
3901
4655
|
handleError(error);
|
|
3902
4656
|
}
|
|
3903
4657
|
});
|
|
3904
4658
|
session.command("show").description("Show the message history of a chat session").argument("<sessionId>", "Session ID").action(async (sessionId, _options, cmd) => {
|
|
3905
4659
|
try {
|
|
3906
|
-
const outputFormat =
|
|
4660
|
+
const outputFormat = getOutputFormat11(cmd);
|
|
3907
4661
|
const api = createApiClient();
|
|
3908
4662
|
const detail = await api.language.getSession(sessionId);
|
|
3909
4663
|
if (outputFormat === "human") {
|
|
3910
|
-
console.log(
|
|
4664
|
+
console.log(chalk20.bold(detail.title) + chalk20.dim(` (${detail.sessionId})`));
|
|
3911
4665
|
console.log();
|
|
3912
4666
|
for (const msg of detail.messages) {
|
|
3913
|
-
const role = msg.role === "user" ?
|
|
3914
|
-
console.log(`${role} ${
|
|
4667
|
+
const role = msg.role === "user" ? chalk20.cyan.bold("You") : chalk20.magenta.bold("Diafunc");
|
|
4668
|
+
console.log(`${role} ${chalk20.dim(msg.created)}`);
|
|
3915
4669
|
console.log(msg.content);
|
|
3916
4670
|
console.log();
|
|
3917
4671
|
}
|
|
@@ -3926,14 +4680,14 @@ Error: ${event.content}`));
|
|
|
3926
4680
|
try {
|
|
3927
4681
|
const api = createApiClient();
|
|
3928
4682
|
await api.language.renameSession(sessionId, title);
|
|
3929
|
-
console.log(
|
|
4683
|
+
console.log(chalk20.green(`Session "${sessionId}" renamed to "${title}".`));
|
|
3930
4684
|
} catch (error) {
|
|
3931
4685
|
handleError(error);
|
|
3932
4686
|
}
|
|
3933
4687
|
});
|
|
3934
4688
|
chat.command("usage").description("Show token usage").action(async (_options, cmd) => {
|
|
3935
4689
|
try {
|
|
3936
|
-
const outputFormat =
|
|
4690
|
+
const outputFormat = getOutputFormat11(cmd);
|
|
3937
4691
|
const api = createApiClient();
|
|
3938
4692
|
const usage = await api.language.getUsage();
|
|
3939
4693
|
format(usage, { format: outputFormat });
|
|
@@ -3944,7 +4698,7 @@ Error: ${event.content}`));
|
|
|
3944
4698
|
}
|
|
3945
4699
|
|
|
3946
4700
|
// src/commands/search/index.ts
|
|
3947
|
-
function
|
|
4701
|
+
function getOutputFormat12(cmd) {
|
|
3948
4702
|
const config = loadConfig();
|
|
3949
4703
|
const globalOpts = cmd.optsWithGlobals();
|
|
3950
4704
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -3952,7 +4706,7 @@ function getOutputFormat11(cmd) {
|
|
|
3952
4706
|
function registerSearchCommands(program) {
|
|
3953
4707
|
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) => {
|
|
3954
4708
|
try {
|
|
3955
|
-
const outputFormat =
|
|
4709
|
+
const outputFormat = getOutputFormat12(cmd);
|
|
3956
4710
|
const api = createApiClient();
|
|
3957
4711
|
if (options.project) {
|
|
3958
4712
|
const results = await api.storage.searchProject(
|
|
@@ -3983,8 +4737,8 @@ function registerSearchCommands(program) {
|
|
|
3983
4737
|
}
|
|
3984
4738
|
|
|
3985
4739
|
// src/commands/group/index.ts
|
|
3986
|
-
import
|
|
3987
|
-
function
|
|
4740
|
+
import chalk21 from "chalk";
|
|
4741
|
+
function getOutputFormat13(cmd) {
|
|
3988
4742
|
const config = loadConfig();
|
|
3989
4743
|
const globalOpts = cmd.optsWithGlobals();
|
|
3990
4744
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -3993,7 +4747,7 @@ function registerGroupCommands(program) {
|
|
|
3993
4747
|
const group = program.command("group").description("Manage groups");
|
|
3994
4748
|
group.command("list").description("List groups").option("--all", "List all groups (admin)").action(async (options, cmd) => {
|
|
3995
4749
|
try {
|
|
3996
|
-
const outputFormat =
|
|
4750
|
+
const outputFormat = getOutputFormat13(cmd);
|
|
3997
4751
|
const api = createApiClient();
|
|
3998
4752
|
const groups = options.all ? await api.admin.getAllGroups() : await api.admin.getGroups();
|
|
3999
4753
|
format(groups, { format: outputFormat, columns: ["groupId", "name"] });
|
|
@@ -4003,7 +4757,7 @@ function registerGroupCommands(program) {
|
|
|
4003
4757
|
});
|
|
4004
4758
|
group.command("get").description("Get group details").argument("<groupId>", "Group ID").action(async (groupId, _options, cmd) => {
|
|
4005
4759
|
try {
|
|
4006
|
-
const outputFormat =
|
|
4760
|
+
const outputFormat = getOutputFormat13(cmd);
|
|
4007
4761
|
const api = createApiClient();
|
|
4008
4762
|
const g = await api.admin.getGroup(groupId);
|
|
4009
4763
|
format(g, { format: outputFormat });
|
|
@@ -4015,7 +4769,7 @@ function registerGroupCommands(program) {
|
|
|
4015
4769
|
try {
|
|
4016
4770
|
const api = createApiClient();
|
|
4017
4771
|
await api.admin.createGroup({ groupId, name: options.name ?? groupId });
|
|
4018
|
-
console.log(
|
|
4772
|
+
console.log(chalk21.green(`Group "${groupId}" created.`));
|
|
4019
4773
|
} catch (error) {
|
|
4020
4774
|
handleError(error);
|
|
4021
4775
|
}
|
|
@@ -4024,7 +4778,7 @@ function registerGroupCommands(program) {
|
|
|
4024
4778
|
try {
|
|
4025
4779
|
const api = createApiClient();
|
|
4026
4780
|
await api.admin.updateGroup({ groupId, name: options.name });
|
|
4027
|
-
console.log(
|
|
4781
|
+
console.log(chalk21.green(`Group "${groupId}" updated.`));
|
|
4028
4782
|
} catch (error) {
|
|
4029
4783
|
handleError(error);
|
|
4030
4784
|
}
|
|
@@ -4033,7 +4787,7 @@ function registerGroupCommands(program) {
|
|
|
4033
4787
|
try {
|
|
4034
4788
|
const api = createApiClient();
|
|
4035
4789
|
await api.admin.deleteGroup(groupId);
|
|
4036
|
-
console.log(
|
|
4790
|
+
console.log(chalk21.green(`Group "${groupId}" deleted.`));
|
|
4037
4791
|
} catch (error) {
|
|
4038
4792
|
handleError(error);
|
|
4039
4793
|
}
|
|
@@ -4041,7 +4795,7 @@ function registerGroupCommands(program) {
|
|
|
4041
4795
|
const members = group.command("members").description("Manage group members");
|
|
4042
4796
|
members.command("list").description("List group members").argument("<groupId>", "Group ID").action(async (groupId, _options, cmd) => {
|
|
4043
4797
|
try {
|
|
4044
|
-
const outputFormat =
|
|
4798
|
+
const outputFormat = getOutputFormat13(cmd);
|
|
4045
4799
|
const api = createApiClient();
|
|
4046
4800
|
const memberList = await api.admin.getGroupMembers(groupId);
|
|
4047
4801
|
format(memberList, { format: outputFormat, columns: ["userId", "role", "joined"] });
|
|
@@ -4053,7 +4807,7 @@ function registerGroupCommands(program) {
|
|
|
4053
4807
|
try {
|
|
4054
4808
|
const api = createApiClient();
|
|
4055
4809
|
await api.admin.inviteGroupMember(groupId, userId, role.toUpperCase());
|
|
4056
|
-
console.log(
|
|
4810
|
+
console.log(chalk21.green(`Invited ${userId} to group "${groupId}" as ${role.toUpperCase()}.`));
|
|
4057
4811
|
} catch (error) {
|
|
4058
4812
|
handleError(error);
|
|
4059
4813
|
}
|
|
@@ -4062,7 +4816,7 @@ function registerGroupCommands(program) {
|
|
|
4062
4816
|
try {
|
|
4063
4817
|
const api = createApiClient();
|
|
4064
4818
|
await api.admin.removeGroupMember(groupId, userId);
|
|
4065
|
-
console.log(
|
|
4819
|
+
console.log(chalk21.green(`Removed ${userId} from group "${groupId}".`));
|
|
4066
4820
|
} catch (error) {
|
|
4067
4821
|
handleError(error);
|
|
4068
4822
|
}
|
|
@@ -4070,7 +4824,7 @@ function registerGroupCommands(program) {
|
|
|
4070
4824
|
const projects = group.command("projects").description("Manage group projects");
|
|
4071
4825
|
projects.command("list").description("List group projects").argument("<groupId>", "Group ID").action(async (groupId, _options, cmd) => {
|
|
4072
4826
|
try {
|
|
4073
|
-
const outputFormat =
|
|
4827
|
+
const outputFormat = getOutputFormat13(cmd);
|
|
4074
4828
|
const api = createApiClient();
|
|
4075
4829
|
const projectList = await api.admin.getGroupProjects(groupId);
|
|
4076
4830
|
format(projectList, { format: outputFormat, columns: ["projectId", "visibility", "language"] });
|
|
@@ -4082,7 +4836,7 @@ function registerGroupCommands(program) {
|
|
|
4082
4836
|
try {
|
|
4083
4837
|
const api = createApiClient();
|
|
4084
4838
|
await api.admin.addGroupProject(groupId, projectId);
|
|
4085
|
-
console.log(
|
|
4839
|
+
console.log(chalk21.green(`Project "${projectId}" added to group "${groupId}".`));
|
|
4086
4840
|
} catch (error) {
|
|
4087
4841
|
handleError(error);
|
|
4088
4842
|
}
|
|
@@ -4091,7 +4845,7 @@ function registerGroupCommands(program) {
|
|
|
4091
4845
|
try {
|
|
4092
4846
|
const api = createApiClient();
|
|
4093
4847
|
await api.admin.removeGroupProject(groupId, projectId);
|
|
4094
|
-
console.log(
|
|
4848
|
+
console.log(chalk21.green(`Project "${projectId}" removed from group "${groupId}".`));
|
|
4095
4849
|
} catch (error) {
|
|
4096
4850
|
handleError(error);
|
|
4097
4851
|
}
|
|
@@ -4099,8 +4853,8 @@ function registerGroupCommands(program) {
|
|
|
4099
4853
|
}
|
|
4100
4854
|
|
|
4101
4855
|
// src/commands/admin/index.ts
|
|
4102
|
-
import
|
|
4103
|
-
function
|
|
4856
|
+
import chalk22 from "chalk";
|
|
4857
|
+
function getOutputFormat14(cmd) {
|
|
4104
4858
|
const config = loadConfig();
|
|
4105
4859
|
const globalOpts = cmd.optsWithGlobals();
|
|
4106
4860
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -4110,7 +4864,7 @@ function registerAdminCommands(program) {
|
|
|
4110
4864
|
const users = admin.command("users").description("Manage users");
|
|
4111
4865
|
users.command("list").description("List all users (admin)").action(async (_options, cmd) => {
|
|
4112
4866
|
try {
|
|
4113
|
-
const outputFormat =
|
|
4867
|
+
const outputFormat = getOutputFormat14(cmd);
|
|
4114
4868
|
const api = createApiClient();
|
|
4115
4869
|
const userList = await api.admin.getUsers();
|
|
4116
4870
|
const summary = userList.map((u) => ({
|
|
@@ -4130,7 +4884,7 @@ function registerAdminCommands(program) {
|
|
|
4130
4884
|
});
|
|
4131
4885
|
users.command("get").description("Get current user details").action(async (_options, cmd) => {
|
|
4132
4886
|
try {
|
|
4133
|
-
const outputFormat =
|
|
4887
|
+
const outputFormat = getOutputFormat14(cmd);
|
|
4134
4888
|
const api = createApiClient();
|
|
4135
4889
|
const user = await api.admin.getMyUser();
|
|
4136
4890
|
format(user, { format: outputFormat });
|
|
@@ -4140,7 +4894,7 @@ function registerAdminCommands(program) {
|
|
|
4140
4894
|
});
|
|
4141
4895
|
admin.command("subscription").description("Show current subscription").action(async (_options, cmd) => {
|
|
4142
4896
|
try {
|
|
4143
|
-
const outputFormat =
|
|
4897
|
+
const outputFormat = getOutputFormat14(cmd);
|
|
4144
4898
|
const api = createApiClient();
|
|
4145
4899
|
const sub = await api.admin.getCurrentSubscription();
|
|
4146
4900
|
format(sub, { format: outputFormat });
|
|
@@ -4151,7 +4905,7 @@ function registerAdminCommands(program) {
|
|
|
4151
4905
|
const settings = admin.command("settings").description("Manage settings");
|
|
4152
4906
|
settings.command("get").description("Get current settings").action(async (_options, cmd) => {
|
|
4153
4907
|
try {
|
|
4154
|
-
const outputFormat =
|
|
4908
|
+
const outputFormat = getOutputFormat14(cmd);
|
|
4155
4909
|
const api = createApiClient();
|
|
4156
4910
|
const s = await api.admin.getSettings();
|
|
4157
4911
|
format(s, { format: outputFormat });
|
|
@@ -4163,7 +4917,7 @@ function registerAdminCommands(program) {
|
|
|
4163
4917
|
try {
|
|
4164
4918
|
const api = createApiClient();
|
|
4165
4919
|
await api.admin.mergeSetting({ [key]: value });
|
|
4166
|
-
console.log(
|
|
4920
|
+
console.log(chalk22.green(`Setting "${key}" updated.`));
|
|
4167
4921
|
} catch (error) {
|
|
4168
4922
|
handleError(error);
|
|
4169
4923
|
}
|
|
@@ -4174,10 +4928,10 @@ function registerAdminCommands(program) {
|
|
|
4174
4928
|
const api = createApiClient();
|
|
4175
4929
|
if (options.longTerm) {
|
|
4176
4930
|
await api.storage.createLongTermFullBackup();
|
|
4177
|
-
console.log(
|
|
4931
|
+
console.log(chalk22.green("Full long-term backup initiated."));
|
|
4178
4932
|
} else {
|
|
4179
4933
|
await api.storage.createShortTermFullBackup();
|
|
4180
|
-
console.log(
|
|
4934
|
+
console.log(chalk22.green("Full short-term backup initiated."));
|
|
4181
4935
|
}
|
|
4182
4936
|
} catch (error) {
|
|
4183
4937
|
handleError(error);
|
|
@@ -4188,29 +4942,37 @@ function registerAdminCommands(program) {
|
|
|
4188
4942
|
const api = createApiClient();
|
|
4189
4943
|
if (options.longTerm) {
|
|
4190
4944
|
await api.storage.createLongTermProjectBackup();
|
|
4191
|
-
console.log(
|
|
4945
|
+
console.log(chalk22.green("Project long-term backup initiated."));
|
|
4192
4946
|
} else {
|
|
4193
4947
|
await api.storage.createShortTermProjectBackup();
|
|
4194
|
-
console.log(
|
|
4948
|
+
console.log(chalk22.green("Project short-term backup initiated."));
|
|
4195
4949
|
}
|
|
4196
4950
|
} catch (error) {
|
|
4197
4951
|
handleError(error);
|
|
4198
4952
|
}
|
|
4199
4953
|
});
|
|
4200
|
-
backup.command("restore-project").description("Restore a project from a backup bucket+object").argument("<projectId>", "Project ID").argument("<projectBranch>", "Project branch").argument("<bucketName>", "Backup bucket name").argument("<objectName>", "Backup object name").action(async (projectId, projectBranch, bucketName, objectName) => {
|
|
4954
|
+
backup.command("restore-project").description("Restore a project from a backup bucket+object").argument("<projectId>", "Project ID").argument("<projectBranch>", "Project branch").argument("<bucketName>", "Backup bucket name").argument("<objectName>", "Backup object name").option("-y, --yes", "Skip confirmation prompt (for CI / scripted use)").action(async (projectId, projectBranch, bucketName, objectName, options) => {
|
|
4201
4955
|
try {
|
|
4956
|
+
await confirmDestructive(
|
|
4957
|
+
`This will overwrite project "${projectId}/${projectBranch}" with backup ${bucketName}/${objectName}.`,
|
|
4958
|
+
{ yes: options.yes }
|
|
4959
|
+
);
|
|
4202
4960
|
const api = createApiClient();
|
|
4203
4961
|
await api.storage.restoreProjectBackup({ projectId, projectBranch, bucketName, objectName });
|
|
4204
|
-
console.log(
|
|
4962
|
+
console.log(chalk22.green(`Restore initiated for ${projectId}/${projectBranch} from ${bucketName}/${objectName}.`));
|
|
4205
4963
|
} catch (error) {
|
|
4206
4964
|
handleError(error);
|
|
4207
4965
|
}
|
|
4208
4966
|
});
|
|
4209
|
-
backup.command("restore-full").description("Restore a full system backup from a bucket+object").argument("<bucketName>", "Backup bucket name").argument("<objectName>", "Backup object name").action(async (bucketName, objectName) => {
|
|
4967
|
+
backup.command("restore-full").description("Restore a full system backup from a bucket+object").argument("<bucketName>", "Backup bucket name").argument("<objectName>", "Backup object name").option("-y, --yes", "Skip confirmation prompt (for CI / scripted use)").action(async (bucketName, objectName, options) => {
|
|
4210
4968
|
try {
|
|
4969
|
+
await confirmDestructive(
|
|
4970
|
+
`This will overwrite the ENTIRE system with backup ${bucketName}/${objectName}.`,
|
|
4971
|
+
{ yes: options.yes }
|
|
4972
|
+
);
|
|
4211
4973
|
const api = createApiClient();
|
|
4212
4974
|
await api.storage.restoreFullBackup({ bucketName, objectName });
|
|
4213
|
-
console.log(
|
|
4975
|
+
console.log(chalk22.green(`Full restore initiated from ${bucketName}/${objectName}.`));
|
|
4214
4976
|
} catch (error) {
|
|
4215
4977
|
handleError(error);
|
|
4216
4978
|
}
|
|
@@ -4220,10 +4982,10 @@ function registerAdminCommands(program) {
|
|
|
4220
4982
|
const api = createApiClient();
|
|
4221
4983
|
if (options.project) {
|
|
4222
4984
|
await api.index.rebuildProject(options.project);
|
|
4223
|
-
console.log(
|
|
4985
|
+
console.log(chalk22.green(`Index rebuild initiated for project "${options.project}".`));
|
|
4224
4986
|
} else {
|
|
4225
4987
|
await api.index.rebuildAll();
|
|
4226
|
-
console.log(
|
|
4988
|
+
console.log(chalk22.green("Index rebuild initiated for all projects."));
|
|
4227
4989
|
}
|
|
4228
4990
|
} catch (error) {
|
|
4229
4991
|
handleError(error);
|
|
@@ -4231,7 +4993,7 @@ function registerAdminCommands(program) {
|
|
|
4231
4993
|
});
|
|
4232
4994
|
admin.command("permissions").description("Show your permissions on a project").argument("<projectId>", "Project ID").action(async (projectId, _options, cmd) => {
|
|
4233
4995
|
try {
|
|
4234
|
-
const outputFormat =
|
|
4996
|
+
const outputFormat = getOutputFormat14(cmd);
|
|
4235
4997
|
const api = createApiClient();
|
|
4236
4998
|
const perm = await api.admin.getPermissions(projectId);
|
|
4237
4999
|
format(perm, { format: outputFormat });
|
|
@@ -4242,14 +5004,14 @@ function registerAdminCommands(program) {
|
|
|
4242
5004
|
}
|
|
4243
5005
|
|
|
4244
5006
|
// src/commands/status/summary.ts
|
|
4245
|
-
import
|
|
5007
|
+
import chalk23 from "chalk";
|
|
4246
5008
|
|
|
4247
5009
|
// src/client/services/status.ts
|
|
4248
5010
|
function createStatusService() {
|
|
4249
5011
|
const config = loadConfig();
|
|
4250
5012
|
const endpoint = resolveEndpoint(config);
|
|
4251
|
-
async function fetchJson(
|
|
4252
|
-
const url = `${endpoint}/status/v1${
|
|
5013
|
+
async function fetchJson(path11) {
|
|
5014
|
+
const url = `${endpoint}/status/v1${path11}`;
|
|
4253
5015
|
const response = await fetch(url, {
|
|
4254
5016
|
headers: { "Accept": "application/json" }
|
|
4255
5017
|
});
|
|
@@ -4268,24 +5030,24 @@ function createStatusService() {
|
|
|
4268
5030
|
|
|
4269
5031
|
// src/commands/status/summary.ts
|
|
4270
5032
|
var STATE_COLORS = {
|
|
4271
|
-
UP:
|
|
4272
|
-
DEGRADED:
|
|
4273
|
-
DOWN:
|
|
4274
|
-
UNKNOWN:
|
|
5033
|
+
UP: chalk23.green,
|
|
5034
|
+
DEGRADED: chalk23.yellow,
|
|
5035
|
+
DOWN: chalk23.red,
|
|
5036
|
+
UNKNOWN: chalk23.gray
|
|
4275
5037
|
};
|
|
4276
5038
|
function stateColor(state) {
|
|
4277
|
-
return STATE_COLORS[state] ??
|
|
5039
|
+
return STATE_COLORS[state] ?? chalk23.gray;
|
|
4278
5040
|
}
|
|
4279
5041
|
function stateSymbol(state) {
|
|
4280
5042
|
switch (state) {
|
|
4281
5043
|
case "UP":
|
|
4282
|
-
return
|
|
5044
|
+
return chalk23.green("\u25CF");
|
|
4283
5045
|
case "DEGRADED":
|
|
4284
|
-
return
|
|
5046
|
+
return chalk23.yellow("\u25CF");
|
|
4285
5047
|
case "DOWN":
|
|
4286
|
-
return
|
|
5048
|
+
return chalk23.red("\u25CF");
|
|
4287
5049
|
default:
|
|
4288
|
-
return
|
|
5050
|
+
return chalk23.gray("\u25CB");
|
|
4289
5051
|
}
|
|
4290
5052
|
}
|
|
4291
5053
|
function registerSummaryCommand(parent) {
|
|
@@ -4312,11 +5074,11 @@ function registerSummaryCommand(parent) {
|
|
|
4312
5074
|
}
|
|
4313
5075
|
console.log();
|
|
4314
5076
|
if (summary.openIncidents > 0) {
|
|
4315
|
-
console.log(
|
|
5077
|
+
console.log(chalk23.yellow(` ${summary.openIncidents} active incident(s)`));
|
|
4316
5078
|
} else {
|
|
4317
|
-
console.log(
|
|
5079
|
+
console.log(chalk23.dim(" No active incidents"));
|
|
4318
5080
|
}
|
|
4319
|
-
console.log(
|
|
5081
|
+
console.log(chalk23.dim(`
|
|
4320
5082
|
Platform v${version.platformVersion} \u2022 ${new Date(summary.timestamp).toLocaleString()}`));
|
|
4321
5083
|
console.log();
|
|
4322
5084
|
} catch (error) {
|
|
@@ -4326,17 +5088,17 @@ function registerSummaryCommand(parent) {
|
|
|
4326
5088
|
}
|
|
4327
5089
|
|
|
4328
5090
|
// src/commands/status/component.ts
|
|
4329
|
-
import
|
|
5091
|
+
import chalk24 from "chalk";
|
|
4330
5092
|
function stateSymbol2(state) {
|
|
4331
5093
|
switch (state) {
|
|
4332
5094
|
case "UP":
|
|
4333
|
-
return
|
|
5095
|
+
return chalk24.green("\u25CF");
|
|
4334
5096
|
case "DEGRADED":
|
|
4335
|
-
return
|
|
5097
|
+
return chalk24.yellow("\u25CF");
|
|
4336
5098
|
case "DOWN":
|
|
4337
|
-
return
|
|
5099
|
+
return chalk24.red("\u25CF");
|
|
4338
5100
|
default:
|
|
4339
|
-
return
|
|
5101
|
+
return chalk24.gray("\u25CB");
|
|
4340
5102
|
}
|
|
4341
5103
|
}
|
|
4342
5104
|
function registerComponentCommand(parent) {
|
|
@@ -4349,7 +5111,7 @@ function registerComponentCommand(parent) {
|
|
|
4349
5111
|
const match = components.find((c) => c.id === id || c.id === id + "-service");
|
|
4350
5112
|
if (!match) {
|
|
4351
5113
|
const available = components.map((c) => c.id).join(", ");
|
|
4352
|
-
console.error(
|
|
5114
|
+
console.error(chalk24.red(`Component "${id}" not found. Available: ${available}`));
|
|
4353
5115
|
process.exit(1);
|
|
4354
5116
|
}
|
|
4355
5117
|
if (outputFormat !== "human") {
|
|
@@ -4357,7 +5119,7 @@ function registerComponentCommand(parent) {
|
|
|
4357
5119
|
return;
|
|
4358
5120
|
}
|
|
4359
5121
|
console.log();
|
|
4360
|
-
console.log(` ${stateSymbol2(match.state)} ${
|
|
5122
|
+
console.log(` ${stateSymbol2(match.state)} ${chalk24.bold(match.id)} ${match.version ? chalk24.dim("v" + match.version) : ""}`);
|
|
4361
5123
|
console.log(` State: ${match.state}`);
|
|
4362
5124
|
if (match.lastCheckAt) {
|
|
4363
5125
|
console.log(` Last check: ${new Date(match.lastCheckAt).toLocaleString()}`);
|
|
@@ -4366,7 +5128,7 @@ function registerComponentCommand(parent) {
|
|
|
4366
5128
|
console.log();
|
|
4367
5129
|
console.log(" Checks:");
|
|
4368
5130
|
for (const check of match.checks) {
|
|
4369
|
-
const cat = check.category ?
|
|
5131
|
+
const cat = check.category ? chalk24.dim(` (${check.category})`) : "";
|
|
4370
5132
|
console.log(` ${stateSymbol2(check.state)} ${check.name}${cat}`);
|
|
4371
5133
|
}
|
|
4372
5134
|
}
|
|
@@ -4378,12 +5140,12 @@ function registerComponentCommand(parent) {
|
|
|
4378
5140
|
}
|
|
4379
5141
|
|
|
4380
5142
|
// src/commands/status/incidents.ts
|
|
4381
|
-
import
|
|
5143
|
+
import chalk25 from "chalk";
|
|
4382
5144
|
var SEVERITY_COLORS = {
|
|
4383
|
-
ERROR:
|
|
4384
|
-
WARNING:
|
|
4385
|
-
INFO:
|
|
4386
|
-
MAINTENANCE:
|
|
5145
|
+
ERROR: chalk25.red,
|
|
5146
|
+
WARNING: chalk25.yellow,
|
|
5147
|
+
INFO: chalk25.blue,
|
|
5148
|
+
MAINTENANCE: chalk25.cyan
|
|
4387
5149
|
};
|
|
4388
5150
|
function registerIncidentsCommand(parent) {
|
|
4389
5151
|
parent.command("incidents").description("List recent incidents").option("-w, --window <window>", "Time window (e.g. 24h, 48h)", "24h").action(async (options, cmd) => {
|
|
@@ -4397,22 +5159,22 @@ function registerIncidentsCommand(parent) {
|
|
|
4397
5159
|
return;
|
|
4398
5160
|
}
|
|
4399
5161
|
if (incidents.length === 0) {
|
|
4400
|
-
console.log(
|
|
5162
|
+
console.log(chalk25.dim(`
|
|
4401
5163
|
No incidents in the last ${options.window}.
|
|
4402
5164
|
`));
|
|
4403
5165
|
return;
|
|
4404
5166
|
}
|
|
4405
5167
|
console.log();
|
|
4406
5168
|
for (const incident of incidents) {
|
|
4407
|
-
const color = SEVERITY_COLORS[incident.severity] ??
|
|
5169
|
+
const color = SEVERITY_COLORS[incident.severity] ?? chalk25.gray;
|
|
4408
5170
|
const severity = color(incident.severity.padEnd(8));
|
|
4409
5171
|
const time = incident.startedAt ? new Date(incident.startedAt).toLocaleString() : "";
|
|
4410
|
-
const resolved = incident.resolvedAt ?
|
|
5172
|
+
const resolved = incident.resolvedAt ? chalk25.green(" [resolved]") : chalk25.yellow(" [open]");
|
|
4411
5173
|
console.log(` ${severity} ${incident.summary}${resolved}`);
|
|
4412
|
-
console.log(
|
|
5174
|
+
console.log(chalk25.dim(` ${time}`));
|
|
4413
5175
|
for (const update of incident.updates) {
|
|
4414
5176
|
const updateTime = new Date(update.at).toLocaleTimeString();
|
|
4415
|
-
console.log(
|
|
5177
|
+
console.log(chalk25.dim(` ${updateTime} ${update.status} ${update.message}`));
|
|
4416
5178
|
}
|
|
4417
5179
|
console.log();
|
|
4418
5180
|
}
|
|
@@ -4431,9 +5193,9 @@ function registerStatusCommands(program) {
|
|
|
4431
5193
|
}
|
|
4432
5194
|
|
|
4433
5195
|
// src/commands/analyze/index.ts
|
|
4434
|
-
import
|
|
4435
|
-
import * as
|
|
4436
|
-
import * as
|
|
5196
|
+
import chalk26 from "chalk";
|
|
5197
|
+
import * as fs8 from "fs";
|
|
5198
|
+
import * as path7 from "path";
|
|
4437
5199
|
import { spawn as spawn2 } from "child_process";
|
|
4438
5200
|
function formatDuration(ms) {
|
|
4439
5201
|
const seconds = Math.floor(ms / 1e3);
|
|
@@ -4448,7 +5210,7 @@ function openUrl(url) {
|
|
|
4448
5210
|
const args = process.platform === "win32" ? ["/c", "start", '""', url] : [url];
|
|
4449
5211
|
spawn2(cmd, args, { detached: true, stdio: "ignore" }).unref();
|
|
4450
5212
|
}
|
|
4451
|
-
function
|
|
5213
|
+
function getOutputFormat15(cmd) {
|
|
4452
5214
|
const config = loadConfig();
|
|
4453
5215
|
const globalOpts = cmd.optsWithGlobals();
|
|
4454
5216
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -4468,48 +5230,64 @@ function isTerminalState(state) {
|
|
|
4468
5230
|
return state === "COMPLETED" || state === "FAILED" || state === "CANCELLED";
|
|
4469
5231
|
}
|
|
4470
5232
|
function multipartFromFile(file) {
|
|
4471
|
-
const buffer =
|
|
5233
|
+
const buffer = fs8.readFileSync(file);
|
|
4472
5234
|
const blob = new Blob([buffer]);
|
|
4473
5235
|
const formData = new FormData();
|
|
4474
|
-
formData.append("content", blob,
|
|
5236
|
+
formData.append("content", blob, path7.basename(file));
|
|
4475
5237
|
return formData;
|
|
4476
5238
|
}
|
|
4477
5239
|
async function runAnalysis(file, options, cmd) {
|
|
4478
|
-
if (!
|
|
4479
|
-
console.error(
|
|
5240
|
+
if (!fs8.existsSync(file)) {
|
|
5241
|
+
console.error(chalk26.red(`File not found: ${file}`));
|
|
4480
5242
|
process.exit(1);
|
|
4481
5243
|
}
|
|
5244
|
+
if (options.preset) {
|
|
5245
|
+
const api2 = createApiClient();
|
|
5246
|
+
const opt = await api2.analysis.getPreset(options.preset);
|
|
5247
|
+
if (!opt.preset) {
|
|
5248
|
+
console.error(chalk26.red(`Preset not found: ${options.preset}`));
|
|
5249
|
+
process.exit(1);
|
|
5250
|
+
}
|
|
5251
|
+
const p = opt.preset;
|
|
5252
|
+
if (options.targets === void 0 && p.targetKeys.length > 0) options.targets = p.targetKeys.join(",");
|
|
5253
|
+
if (options.questions === void 0 && p.questions.length > 0) options.questions = p.questions.join(",");
|
|
5254
|
+
if (options.segment === void 0 && p.segmentKey) options.segment = p.segmentKey;
|
|
5255
|
+
if (options.hours === void 0) options.hours = p.time;
|
|
5256
|
+
if (options.budget === void 0) options.budget = p.budget;
|
|
5257
|
+
}
|
|
5258
|
+
const hours = options.hours ?? "4";
|
|
5259
|
+
const budget = options.budget ?? "400";
|
|
4482
5260
|
const api = createApiClient();
|
|
4483
5261
|
const visibility = parseVisibility(options.visibility);
|
|
4484
|
-
const name = options.name ??
|
|
5262
|
+
const name = options.name ?? path7.basename(file, path7.extname(file));
|
|
4485
5263
|
const request = {
|
|
4486
5264
|
name,
|
|
4487
5265
|
description: options.description || null,
|
|
4488
5266
|
visibility,
|
|
4489
5267
|
introduction: options.introduction ?? null,
|
|
4490
|
-
hours
|
|
4491
|
-
budget
|
|
5268
|
+
hours,
|
|
5269
|
+
budget,
|
|
4492
5270
|
targets: parseCsv(options.targets),
|
|
4493
5271
|
questions: parseCsv(options.questions),
|
|
4494
5272
|
segment: options.segment ?? null
|
|
4495
5273
|
};
|
|
4496
5274
|
process.stdout.write(`Creating analysis "${name}" ...`);
|
|
4497
5275
|
const created = await api.analysis.create(request);
|
|
4498
|
-
console.log(
|
|
4499
|
-
console.log(
|
|
4500
|
-
process.stdout.write(`Uploading ${
|
|
5276
|
+
console.log(chalk26.green(" done"));
|
|
5277
|
+
console.log(chalk26.dim(` analysisId: ${created.analysisId}`));
|
|
5278
|
+
process.stdout.write(`Uploading ${path7.basename(file)} ...`);
|
|
4501
5279
|
await api.analysis.uploadDataMultipart(created.analysisId, multipartFromFile(file));
|
|
4502
|
-
console.log(
|
|
5280
|
+
console.log(chalk26.green(" done"));
|
|
4503
5281
|
process.stdout.write("Queuing analysis run ...");
|
|
4504
5282
|
const run = await api.analysis.runAnalysis(created.analysisId);
|
|
4505
|
-
console.log(
|
|
4506
|
-
console.log(
|
|
5283
|
+
console.log(chalk26.green(" done"));
|
|
5284
|
+
console.log(chalk26.dim(` runId: ${run.runId}`));
|
|
4507
5285
|
console.log();
|
|
4508
|
-
await monitorRun(api, created.analysisId, run.runId, parseFloat(
|
|
5286
|
+
await monitorRun(api, created.analysisId, run.runId, parseFloat(hours), cmd);
|
|
4509
5287
|
}
|
|
4510
5288
|
async function monitorRun(api, analysisId, runId, hoursForProgress, cmd) {
|
|
4511
5289
|
const config = loadConfig();
|
|
4512
|
-
const outputFormat =
|
|
5290
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
4513
5291
|
const computationMs = hoursForProgress * 60 * 60 * 1e3;
|
|
4514
5292
|
const startMs = Date.now();
|
|
4515
5293
|
const seenOutputIds = /* @__PURE__ */ new Set();
|
|
@@ -4528,7 +5306,11 @@ async function monitorRun(api, analysisId, runId, hoursForProgress, cmd) {
|
|
|
4528
5306
|
if (!seenOutputIds.has(out.outputId)) {
|
|
4529
5307
|
seenOutputIds.add(out.outputId);
|
|
4530
5308
|
if (outputFormat === "human") {
|
|
4531
|
-
console.log(` ${
|
|
5309
|
+
console.log(` ${chalk26.dim("Output:")} ${out.output}`);
|
|
5310
|
+
} else {
|
|
5311
|
+
process.stdout.write(
|
|
5312
|
+
JSON.stringify({ type: "output", outputId: out.outputId, output: out.output }) + "\n"
|
|
5313
|
+
);
|
|
4532
5314
|
}
|
|
4533
5315
|
}
|
|
4534
5316
|
}
|
|
@@ -4541,7 +5323,7 @@ async function monitorRun(api, analysisId, runId, hoursForProgress, cmd) {
|
|
|
4541
5323
|
const durationStr = formatDuration(duration);
|
|
4542
5324
|
if (run.state === "COMPLETED") {
|
|
4543
5325
|
if (outputFormat === "human") {
|
|
4544
|
-
console.log(
|
|
5326
|
+
console.log(chalk26.green(`Analysis complete! (${durationStr})`));
|
|
4545
5327
|
try {
|
|
4546
5328
|
const nav = await api.analysis.getNavigation(analysisId);
|
|
4547
5329
|
const endpoint = config.profiles[config.currentProfile]?.endpoint ?? "https://diafunc.com";
|
|
@@ -4553,13 +5335,13 @@ async function monitorRun(api, analysisId, runId, hoursForProgress, cmd) {
|
|
|
4553
5335
|
}
|
|
4554
5336
|
} else if (run.state === "CANCELLED") {
|
|
4555
5337
|
if (outputFormat === "human") {
|
|
4556
|
-
console.log(
|
|
5338
|
+
console.log(chalk26.yellow("Analysis cancelled."));
|
|
4557
5339
|
} else {
|
|
4558
5340
|
format({ status: "cancelled", runId, analysisId }, { format: outputFormat });
|
|
4559
5341
|
}
|
|
4560
5342
|
} else {
|
|
4561
5343
|
if (outputFormat === "human") {
|
|
4562
|
-
console.log(
|
|
5344
|
+
console.log(chalk26.red("Analysis failed."));
|
|
4563
5345
|
if (run.errorMessage) console.log(` Error: ${run.errorMessage}`);
|
|
4564
5346
|
} else {
|
|
4565
5347
|
format({ status: "failed", runId, analysisId, error: run.errorMessage }, { format: outputFormat });
|
|
@@ -4579,7 +5361,7 @@ async function monitorRun(api, analysisId, runId, hoursForProgress, cmd) {
|
|
|
4579
5361
|
}
|
|
4580
5362
|
}
|
|
4581
5363
|
async function listAnalyses(limit, cmd) {
|
|
4582
|
-
const outputFormat =
|
|
5364
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
4583
5365
|
const api = createApiClient();
|
|
4584
5366
|
const analyses = await api.analysis.getRecent(limit);
|
|
4585
5367
|
format(analyses.map((a) => ({
|
|
@@ -4597,11 +5379,11 @@ async function listAnalyses(limit, cmd) {
|
|
|
4597
5379
|
});
|
|
4598
5380
|
}
|
|
4599
5381
|
async function getAnalysisDetails(analysisId, cmd) {
|
|
4600
|
-
const outputFormat =
|
|
5382
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
4601
5383
|
const api = createApiClient();
|
|
4602
5384
|
const result = analysisId ? await api.analysis.get(analysisId) : await api.analysis.getLast();
|
|
4603
5385
|
if (!result.analysis) {
|
|
4604
|
-
console.log(
|
|
5386
|
+
console.log(chalk26.dim("No analysis found."));
|
|
4605
5387
|
return;
|
|
4606
5388
|
}
|
|
4607
5389
|
format(result.analysis, { format: outputFormat });
|
|
@@ -4610,18 +5392,18 @@ async function watchAnalysis(analysisId, cmd) {
|
|
|
4610
5392
|
const api = createApiClient();
|
|
4611
5393
|
const result = analysisId ? await api.analysis.get(analysisId) : await api.analysis.getLast();
|
|
4612
5394
|
if (!result.analysis) {
|
|
4613
|
-
console.log(
|
|
5395
|
+
console.log(chalk26.dim("No analysis found."));
|
|
4614
5396
|
return;
|
|
4615
5397
|
}
|
|
4616
5398
|
const recipe = result.analysis;
|
|
4617
5399
|
const runs = await api.analysis.getRunsForAnalysis(recipe.analysisId, 1);
|
|
4618
5400
|
if (runs.length === 0) {
|
|
4619
|
-
console.log(
|
|
5401
|
+
console.log(chalk26.dim("No runs for this analysis."));
|
|
4620
5402
|
return;
|
|
4621
5403
|
}
|
|
4622
5404
|
const latest = runs[0];
|
|
4623
5405
|
if (isTerminalState(latest.state)) {
|
|
4624
|
-
console.log(
|
|
5406
|
+
console.log(chalk26.green(`Latest run already in terminal state: ${latest.state}`));
|
|
4625
5407
|
try {
|
|
4626
5408
|
const nav = await api.analysis.getNavigation(recipe.analysisId);
|
|
4627
5409
|
const config = loadConfig();
|
|
@@ -4637,16 +5419,16 @@ async function watchAnalysis(analysisId, cmd) {
|
|
|
4637
5419
|
async function rerunAnalysis(analysisId) {
|
|
4638
5420
|
const api = createApiClient();
|
|
4639
5421
|
const run = await api.analysis.runAnalysis(analysisId);
|
|
4640
|
-
console.log(
|
|
4641
|
-
console.log(
|
|
5422
|
+
console.log(chalk26.green(`\u2713 Queued new run ${run.runId} for analysis ${analysisId}`));
|
|
5423
|
+
console.log(chalk26.dim(` State: ${run.state}`));
|
|
4642
5424
|
console.log();
|
|
4643
|
-
console.log(
|
|
5425
|
+
console.log(chalk26.dim("Track progress: diafunc analyze watch " + analysisId));
|
|
4644
5426
|
}
|
|
4645
5427
|
async function openAnalysis(analysisId) {
|
|
4646
5428
|
const api = createApiClient();
|
|
4647
5429
|
const result = analysisId ? await api.analysis.get(analysisId) : await api.analysis.getLast();
|
|
4648
5430
|
if (!result.analysis) {
|
|
4649
|
-
console.log(
|
|
5431
|
+
console.log(chalk26.dim("No analysis found."));
|
|
4650
5432
|
return;
|
|
4651
5433
|
}
|
|
4652
5434
|
const config = loadConfig();
|
|
@@ -4657,11 +5439,11 @@ async function openAnalysis(analysisId) {
|
|
|
4657
5439
|
console.log(`Opening ${url} ...`);
|
|
4658
5440
|
openUrl(url);
|
|
4659
5441
|
} catch {
|
|
4660
|
-
console.log(
|
|
5442
|
+
console.log(chalk26.dim("Notebook not yet provisioned \u2014 run the analysis first."));
|
|
4661
5443
|
}
|
|
4662
5444
|
}
|
|
4663
5445
|
async function createRecipe(options, cmd) {
|
|
4664
|
-
const outputFormat =
|
|
5446
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
4665
5447
|
const api = createApiClient();
|
|
4666
5448
|
const visibility = parseVisibility(options.visibility);
|
|
4667
5449
|
const request = {
|
|
@@ -4681,14 +5463,14 @@ async function createRecipe(options, cmd) {
|
|
|
4681
5463
|
async function deleteAnalysis(analysisId) {
|
|
4682
5464
|
const api = createApiClient();
|
|
4683
5465
|
await api.analysis.delete(analysisId);
|
|
4684
|
-
console.log(
|
|
5466
|
+
console.log(chalk26.green(`\u2713 Deleted analysis ${analysisId}`));
|
|
4685
5467
|
}
|
|
4686
5468
|
async function patchAndPrint(analysisId, value, handler, successLabel, cmd) {
|
|
4687
|
-
const outputFormat =
|
|
5469
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
4688
5470
|
const api = createApiClient();
|
|
4689
5471
|
const updated = await handler(api, analysisId, value);
|
|
4690
5472
|
if (outputFormat === "human") {
|
|
4691
|
-
console.log(
|
|
5473
|
+
console.log(chalk26.green(`\u2713 ${successLabel} updated for analysis ${analysisId}`));
|
|
4692
5474
|
} else {
|
|
4693
5475
|
format(updated, { format: outputFormat });
|
|
4694
5476
|
}
|
|
@@ -4697,38 +5479,38 @@ async function uploadData(analysisId, file, options) {
|
|
|
4697
5479
|
const api = createApiClient();
|
|
4698
5480
|
if (options.url) {
|
|
4699
5481
|
if (file) {
|
|
4700
|
-
console.error(
|
|
5482
|
+
console.error(chalk26.red("Provide either a file or --url, not both."));
|
|
4701
5483
|
process.exit(1);
|
|
4702
5484
|
}
|
|
4703
5485
|
process.stdout.write(`Uploading from ${options.url} ...`);
|
|
4704
5486
|
await api.analysis.uploadDataUrl(analysisId, { dataUrl: options.url });
|
|
4705
|
-
console.log(
|
|
5487
|
+
console.log(chalk26.green(" done"));
|
|
4706
5488
|
return;
|
|
4707
5489
|
}
|
|
4708
5490
|
if (!file) {
|
|
4709
|
-
console.error(
|
|
5491
|
+
console.error(chalk26.red("Provide a file path or --url <URL>."));
|
|
4710
5492
|
process.exit(1);
|
|
4711
5493
|
}
|
|
4712
|
-
if (!
|
|
4713
|
-
console.error(
|
|
5494
|
+
if (!fs8.existsSync(file)) {
|
|
5495
|
+
console.error(chalk26.red(`File not found: ${file}`));
|
|
4714
5496
|
process.exit(1);
|
|
4715
5497
|
}
|
|
4716
|
-
process.stdout.write(`Uploading ${
|
|
5498
|
+
process.stdout.write(`Uploading ${path7.basename(file)} ...`);
|
|
4717
5499
|
await api.analysis.uploadDataMultipart(analysisId, multipartFromFile(file));
|
|
4718
|
-
console.log(
|
|
5500
|
+
console.log(chalk26.green(" done"));
|
|
4719
5501
|
}
|
|
4720
5502
|
async function listColumns(analysisId, cmd) {
|
|
4721
|
-
const outputFormat =
|
|
5503
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
4722
5504
|
const api = createApiClient();
|
|
4723
5505
|
const columns = await api.analysis.getColumns(analysisId);
|
|
4724
5506
|
if (columns.length === 0) {
|
|
4725
|
-
console.log(
|
|
5507
|
+
console.log(chalk26.dim("No columns yet \u2014 upload data first."));
|
|
4726
5508
|
return;
|
|
4727
5509
|
}
|
|
4728
5510
|
format(columns, { format: outputFormat, columns: ["name", "valueType"] });
|
|
4729
5511
|
}
|
|
4730
5512
|
async function listRuns(analysisId, count, cmd) {
|
|
4731
|
-
const outputFormat =
|
|
5513
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
4732
5514
|
const api = createApiClient();
|
|
4733
5515
|
const runs = await api.analysis.getRunsForAnalysis(analysisId, count);
|
|
4734
5516
|
format(runs.map((r) => ({
|
|
@@ -4744,17 +5526,17 @@ async function listRuns(analysisId, count, cmd) {
|
|
|
4744
5526
|
});
|
|
4745
5527
|
}
|
|
4746
5528
|
async function cancelRun(runId, cmd) {
|
|
4747
|
-
const outputFormat =
|
|
5529
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
4748
5530
|
const api = createApiClient();
|
|
4749
5531
|
const run = await api.analysis.cancelRun(runId);
|
|
4750
5532
|
if (outputFormat === "human") {
|
|
4751
|
-
console.log(
|
|
5533
|
+
console.log(chalk26.green(`\u2713 Run ${run.runId} state: ${run.state}`));
|
|
4752
5534
|
} else {
|
|
4753
5535
|
format(run, { format: outputFormat });
|
|
4754
5536
|
}
|
|
4755
5537
|
}
|
|
4756
5538
|
async function listPresets(cmd) {
|
|
4757
|
-
const outputFormat =
|
|
5539
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
4758
5540
|
const api = createApiClient();
|
|
4759
5541
|
const presets = await api.analysis.getPresets();
|
|
4760
5542
|
format(presets.map((p) => ({
|
|
@@ -4771,17 +5553,17 @@ async function listPresets(cmd) {
|
|
|
4771
5553
|
});
|
|
4772
5554
|
}
|
|
4773
5555
|
async function getPreset(presetId, cmd) {
|
|
4774
|
-
const outputFormat =
|
|
5556
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
4775
5557
|
const api = createApiClient();
|
|
4776
5558
|
const opt = await api.analysis.getPreset(presetId);
|
|
4777
5559
|
if (!opt.preset) {
|
|
4778
|
-
console.log(
|
|
5560
|
+
console.log(chalk26.dim("Preset not found."));
|
|
4779
5561
|
return;
|
|
4780
5562
|
}
|
|
4781
5563
|
format(opt.preset, { format: outputFormat });
|
|
4782
5564
|
}
|
|
4783
5565
|
async function savePreset(options, cmd) {
|
|
4784
|
-
const outputFormat =
|
|
5566
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
4785
5567
|
const api = createApiClient();
|
|
4786
5568
|
const preset = {
|
|
4787
5569
|
presetId: options.id ?? null,
|
|
@@ -4798,10 +5580,10 @@ async function savePreset(options, cmd) {
|
|
|
4798
5580
|
async function deletePreset(presetId) {
|
|
4799
5581
|
const api = createApiClient();
|
|
4800
5582
|
await api.analysis.deletePreset(presetId);
|
|
4801
|
-
console.log(
|
|
5583
|
+
console.log(chalk26.green(`\u2713 Deleted preset ${presetId}`));
|
|
4802
5584
|
}
|
|
4803
5585
|
async function listTriggers(analysisId, cmd) {
|
|
4804
|
-
const outputFormat =
|
|
5586
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
4805
5587
|
const api = createApiClient();
|
|
4806
5588
|
const triggers = await api.analysis.listTriggers(analysisId);
|
|
4807
5589
|
format(triggers.map((t) => ({
|
|
@@ -4816,10 +5598,10 @@ async function listTriggers(analysisId, cmd) {
|
|
|
4816
5598
|
});
|
|
4817
5599
|
}
|
|
4818
5600
|
async function createTrigger(analysisId, kind, schedule, cmd) {
|
|
4819
|
-
const outputFormat =
|
|
5601
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
4820
5602
|
const upper = kind.toUpperCase();
|
|
4821
5603
|
if (upper !== "ONCE" && upper !== "CRON") {
|
|
4822
|
-
console.error(
|
|
5604
|
+
console.error(chalk26.red(`Invalid kind "${kind}" \u2014 must be ONCE or CRON.`));
|
|
4823
5605
|
process.exit(1);
|
|
4824
5606
|
}
|
|
4825
5607
|
const api = createApiClient();
|
|
@@ -4832,21 +5614,21 @@ async function createTrigger(analysisId, kind, schedule, cmd) {
|
|
|
4832
5614
|
async function deleteTrigger(triggerId) {
|
|
4833
5615
|
const api = createApiClient();
|
|
4834
5616
|
await api.analysis.deleteTrigger(triggerId);
|
|
4835
|
-
console.log(
|
|
5617
|
+
console.log(chalk26.green(`\u2713 Deleted trigger ${triggerId}`));
|
|
4836
5618
|
}
|
|
4837
5619
|
async function updateTriggerCmd(triggerId, options, cmd) {
|
|
4838
|
-
const outputFormat =
|
|
5620
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
4839
5621
|
let activeFlag;
|
|
4840
5622
|
if (options.active !== void 0) {
|
|
4841
5623
|
const lc = options.active.toLowerCase();
|
|
4842
5624
|
if (lc !== "true" && lc !== "false") {
|
|
4843
|
-
console.error(
|
|
5625
|
+
console.error(chalk26.red(`Invalid --active value "${options.active}" \u2014 must be true or false.`));
|
|
4844
5626
|
process.exit(1);
|
|
4845
5627
|
}
|
|
4846
5628
|
activeFlag = lc === "true";
|
|
4847
5629
|
}
|
|
4848
5630
|
if (activeFlag === void 0 && !options.schedule) {
|
|
4849
|
-
console.error(
|
|
5631
|
+
console.error(chalk26.red("Pass at least one of --active or --schedule."));
|
|
4850
5632
|
process.exit(1);
|
|
4851
5633
|
}
|
|
4852
5634
|
const api = createApiClient();
|
|
@@ -4858,7 +5640,7 @@ async function updateTriggerCmd(triggerId, options, cmd) {
|
|
|
4858
5640
|
}
|
|
4859
5641
|
function registerAnalyzeCommand(program) {
|
|
4860
5642
|
const analyze = program.command("analyze").description("Run and manage automatic analyses");
|
|
4861
|
-
analyze.argument("[file]", "CSV or Excel file to analyze").option("--name <name>", "Analysis name (derived from filename if omitted)").option("--description <text>", "Analysis description", "").option("--visibility <vis>", "PRIVATE or PUBLIC", "PRIVATE").option("--hours <hours>", "Computation time in hours
|
|
5643
|
+
analyze.argument("[file]", "CSV or Excel file to analyze").option("--name <name>", "Analysis name (derived from filename if omitted)").option("--description <text>", "Analysis description", "").option("--visibility <vis>", "PRIVATE or PUBLIC", "PRIVATE").option("--hours <hours>", "Computation time in hours (default: 4; preset value used when --preset set)").option("--budget <credits>", "Credit budget (default: 400; preset value used when --preset set)").option("--targets <csv>", "Comma-separated target column names").option("--questions <csv>", "Comma-separated questions to answer").option("--segment <name>", "Column to segment the analysis by").option("--introduction <markdown>", "Markdown introduction at notebook position 0").option("--preset <id>", "Apply a saved preset as defaults (explicit flags override preset values)").action(async (file, options, cmd) => {
|
|
4862
5644
|
try {
|
|
4863
5645
|
if (!file) {
|
|
4864
5646
|
analyze.help();
|
|
@@ -4911,8 +5693,9 @@ function registerAnalyzeCommand(program) {
|
|
|
4911
5693
|
handleError(error);
|
|
4912
5694
|
}
|
|
4913
5695
|
});
|
|
4914
|
-
analyze.command("delete").description("Delete an analysis (cancels in-flight run; removes underlying project)").argument("<id>", "Analysis ID").action(async (id) => {
|
|
5696
|
+
analyze.command("delete").description("Delete an analysis (cancels in-flight run; removes underlying project)").argument("<id>", "Analysis ID").option("-y, --yes", "Skip confirmation prompt (for CI / scripted use)").action(async (id, options) => {
|
|
4915
5697
|
try {
|
|
5698
|
+
await confirmDestructive(`This will permanently delete analysis "${id}".`, { yes: options.yes, resourceId: id });
|
|
4916
5699
|
await deleteAnalysis(id);
|
|
4917
5700
|
} catch (error) {
|
|
4918
5701
|
handleError(error);
|
|
@@ -5038,7 +5821,7 @@ function registerAnalyzeCommand(program) {
|
|
|
5038
5821
|
handleError(error);
|
|
5039
5822
|
}
|
|
5040
5823
|
});
|
|
5041
|
-
analyze.command("upload").description("Replace the analysis raw-data table with a new
|
|
5824
|
+
analyze.command("upload").description("Replace the analysis raw-data table with a new data table (any supported format \u2014 see `table import-formats`)").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) => {
|
|
5042
5825
|
try {
|
|
5043
5826
|
await uploadData(id, file, options);
|
|
5044
5827
|
} catch (error) {
|
|
@@ -5088,8 +5871,9 @@ function registerAnalyzeCommand(program) {
|
|
|
5088
5871
|
handleError(error);
|
|
5089
5872
|
}
|
|
5090
5873
|
});
|
|
5091
|
-
presets.command("delete").description("Delete a preset").argument("<id>", "Preset ID").action(async (id) => {
|
|
5874
|
+
presets.command("delete").description("Delete a preset").argument("<id>", "Preset ID").option("-y, --yes", "Skip confirmation prompt (for CI / scripted use)").action(async (id, options) => {
|
|
5092
5875
|
try {
|
|
5876
|
+
await confirmDestructive(`This will permanently delete preset "${id}".`, { yes: options.yes, resourceId: id });
|
|
5093
5877
|
await deletePreset(id);
|
|
5094
5878
|
} catch (error) {
|
|
5095
5879
|
handleError(error);
|
|
@@ -5110,8 +5894,9 @@ function registerAnalyzeCommand(program) {
|
|
|
5110
5894
|
handleError(error);
|
|
5111
5895
|
}
|
|
5112
5896
|
});
|
|
5113
|
-
triggers.command("delete").description("Delete a trigger").argument("<triggerId>", "Trigger ID").action(async (triggerId) => {
|
|
5897
|
+
triggers.command("delete").description("Delete a trigger").argument("<triggerId>", "Trigger ID").option("-y, --yes", "Skip confirmation prompt (for CI / scripted use)").action(async (triggerId, options) => {
|
|
5114
5898
|
try {
|
|
5899
|
+
await confirmDestructive(`This will permanently delete trigger "${triggerId}".`, { yes: options.yes, resourceId: triggerId });
|
|
5115
5900
|
await deleteTrigger(triggerId);
|
|
5116
5901
|
} catch (error) {
|
|
5117
5902
|
handleError(error);
|
|
@@ -5127,8 +5912,8 @@ function registerAnalyzeCommand(program) {
|
|
|
5127
5912
|
}
|
|
5128
5913
|
|
|
5129
5914
|
// src/commands/data-sources/index.ts
|
|
5130
|
-
import
|
|
5131
|
-
function
|
|
5915
|
+
import chalk27 from "chalk";
|
|
5916
|
+
function getOutputFormat16(cmd) {
|
|
5132
5917
|
const config = loadConfig();
|
|
5133
5918
|
const globalOpts = cmd.optsWithGlobals();
|
|
5134
5919
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -5161,6 +5946,49 @@ function dataSourceTableRow(ds) {
|
|
|
5161
5946
|
lastRefreshAt: ds.lastRefreshAt ?? "\u2014"
|
|
5162
5947
|
};
|
|
5163
5948
|
}
|
|
5949
|
+
function formatBytes(bytes) {
|
|
5950
|
+
if (bytes === null || bytes === void 0) return "\u2014";
|
|
5951
|
+
if (bytes < 1e3) return `${bytes} B`;
|
|
5952
|
+
if (bytes < 1e6) return `${(bytes / 1e3).toFixed(1)} kB`;
|
|
5953
|
+
if (bytes < 1e9) return `${(bytes / 1e6).toFixed(2)} MB`;
|
|
5954
|
+
return `${(bytes / 1e9).toFixed(2)} GB`;
|
|
5955
|
+
}
|
|
5956
|
+
function formatCredits(credits) {
|
|
5957
|
+
if (credits === null || credits === void 0) return "\u2014";
|
|
5958
|
+
if (credits === 0) return "0";
|
|
5959
|
+
if (credits < 0.01) return credits.toFixed(4);
|
|
5960
|
+
return credits.toFixed(2);
|
|
5961
|
+
}
|
|
5962
|
+
function humanizeCron(cron) {
|
|
5963
|
+
if (!cron || !cron.trim()) return "manual";
|
|
5964
|
+
const parts = cron.trim().split(/\s+/);
|
|
5965
|
+
if (parts.length < 6) return cron.trim();
|
|
5966
|
+
const [sec, min, hour, dom, mon, dow] = parts;
|
|
5967
|
+
const pad2 = (n) => n.length < 2 ? `0${n}` : n;
|
|
5968
|
+
const everyDay = (dom === "*" || dom === "?") && mon === "*" && (dow === "*" || dow === "?");
|
|
5969
|
+
if (sec === "0" && min === "*" && hour === "*" && everyDay) return "every minute";
|
|
5970
|
+
if (sec === "0" && /^\d+$/.test(min) && hour === "*" && everyDay) {
|
|
5971
|
+
return min === "0" ? "hourly" : `hourly at :${pad2(min)}`;
|
|
5972
|
+
}
|
|
5973
|
+
if (sec === "0" && /^\d+$/.test(min) && /^\d+$/.test(hour) && everyDay) {
|
|
5974
|
+
if (hour === "0" && min === "0") return "daily at midnight UTC";
|
|
5975
|
+
return `daily at ${pad2(hour)}:${pad2(min)} UTC`;
|
|
5976
|
+
}
|
|
5977
|
+
return cron.trim();
|
|
5978
|
+
}
|
|
5979
|
+
function dashboardTableRow(s) {
|
|
5980
|
+
return {
|
|
5981
|
+
id: s.id,
|
|
5982
|
+
name: s.name,
|
|
5983
|
+
type: s.type,
|
|
5984
|
+
schedule: humanizeCron(s.scheduleCron),
|
|
5985
|
+
lastStatus: s.lastRunStatus ?? "\u2014",
|
|
5986
|
+
lastRunAt: s.lastRunAt ?? "\u2014",
|
|
5987
|
+
nextScheduledAt: s.nextScheduledAt ?? "\u2014",
|
|
5988
|
+
recentFailures: `${s.recentFailureCount}/${s.recentRunCount}`,
|
|
5989
|
+
lastTransferred: formatBytes(s.lastBytesFetched)
|
|
5990
|
+
};
|
|
5991
|
+
}
|
|
5164
5992
|
function runTableRow(run) {
|
|
5165
5993
|
return {
|
|
5166
5994
|
runId: run.runId,
|
|
@@ -5168,15 +5996,17 @@ function runTableRow(run) {
|
|
|
5168
5996
|
startedAt: run.startedAt ?? "\u2014",
|
|
5169
5997
|
finishedAt: run.finishedAt ?? "\u2014",
|
|
5170
5998
|
rows: run.rowsImported !== null && run.rowsImported !== void 0 ? String(run.rowsImported) : "\u2014",
|
|
5999
|
+
transferred: formatBytes(run.bytesFetched),
|
|
6000
|
+
credits: formatCredits(run.creditsCharged),
|
|
5171
6001
|
triggeredBy: run.triggeredBy ?? "\u2014"
|
|
5172
6002
|
};
|
|
5173
6003
|
}
|
|
5174
6004
|
async function listDataSources(projectId, cmd) {
|
|
5175
|
-
const outputFormat =
|
|
6005
|
+
const outputFormat = getOutputFormat16(cmd);
|
|
5176
6006
|
const api = createApiClient();
|
|
5177
6007
|
const sources = await api.storage.listDataSources(projectId);
|
|
5178
6008
|
if (outputFormat === "human" && sources.length === 0) {
|
|
5179
|
-
console.log(
|
|
6009
|
+
console.log(chalk27.dim("No data sources found."));
|
|
5180
6010
|
return;
|
|
5181
6011
|
}
|
|
5182
6012
|
format(sources.map(dataSourceTableRow), {
|
|
@@ -5185,13 +6015,34 @@ async function listDataSources(projectId, cmd) {
|
|
|
5185
6015
|
});
|
|
5186
6016
|
}
|
|
5187
6017
|
async function getDataSource(id, cmd) {
|
|
5188
|
-
const outputFormat =
|
|
6018
|
+
const outputFormat = getOutputFormat16(cmd);
|
|
5189
6019
|
const api = createApiClient();
|
|
5190
6020
|
const ds = await api.storage.getDataSource(id);
|
|
5191
6021
|
format(ds, { format: outputFormat });
|
|
5192
6022
|
}
|
|
6023
|
+
async function showDashboard(projectId, cmd) {
|
|
6024
|
+
const outputFormat = getOutputFormat16(cmd);
|
|
6025
|
+
const api = createApiClient();
|
|
6026
|
+
const dashboard = await api.storage.getDataSourceDashboard(projectId);
|
|
6027
|
+
if (outputFormat !== "human") {
|
|
6028
|
+
format(dashboard, { format: outputFormat });
|
|
6029
|
+
return;
|
|
6030
|
+
}
|
|
6031
|
+
const r = dashboard.rollup;
|
|
6032
|
+
let line = chalk27.bold(`DataSources in ${projectId}: `) + `${r.totalSources} total, ${r.scheduledSources} scheduled, ${r.sourcesWithRecentFailure} failing recently`;
|
|
6033
|
+
if (r.lastActivityAt) line += `, last activity ${r.lastActivityAt}`;
|
|
6034
|
+
console.log(line);
|
|
6035
|
+
if (dashboard.sources.length === 0) {
|
|
6036
|
+
console.log(chalk27.dim("No data sources."));
|
|
6037
|
+
return;
|
|
6038
|
+
}
|
|
6039
|
+
format(dashboard.sources.map(dashboardTableRow), {
|
|
6040
|
+
format: outputFormat,
|
|
6041
|
+
columns: ["id", "name", "type", "schedule", "lastStatus", "lastRunAt", "nextScheduledAt", "recentFailures", "lastTransferred"]
|
|
6042
|
+
});
|
|
6043
|
+
}
|
|
5193
6044
|
async function createDataSource(options, cmd) {
|
|
5194
|
-
const outputFormat =
|
|
6045
|
+
const outputFormat = getOutputFormat16(cmd);
|
|
5195
6046
|
const api = createApiClient();
|
|
5196
6047
|
const request = {
|
|
5197
6048
|
projectId: options.projectId,
|
|
@@ -5205,15 +6056,15 @@ async function createDataSource(options, cmd) {
|
|
|
5205
6056
|
};
|
|
5206
6057
|
const ds = await api.storage.createDataSource(request);
|
|
5207
6058
|
if (outputFormat === "human") {
|
|
5208
|
-
console.log(
|
|
5209
|
-
console.log(
|
|
5210
|
-
if (ds.lastRunError) console.log(
|
|
6059
|
+
console.log(chalk27.green(`\u2713 Created data source ${ds.id}`));
|
|
6060
|
+
console.log(chalk27.dim(` Last run: ${ds.lastRunStatus ?? "\u2014"}`));
|
|
6061
|
+
if (ds.lastRunError) console.log(chalk27.dim(` Error: ${ds.lastRunError}`));
|
|
5211
6062
|
} else {
|
|
5212
6063
|
format(ds, { format: outputFormat });
|
|
5213
6064
|
}
|
|
5214
6065
|
}
|
|
5215
6066
|
async function updateDataSource(id, options, cmd) {
|
|
5216
|
-
const outputFormat =
|
|
6067
|
+
const outputFormat = getOutputFormat16(cmd);
|
|
5217
6068
|
if (options.name === void 0 && options.type === void 0 && (!options.config || options.config.length === 0) && options.scheduleCron === void 0 && !options.clearSchedule) {
|
|
5218
6069
|
throw new Error("Provide at least one of --name, --type, --config, --schedule-cron, or --clear-schedule.");
|
|
5219
6070
|
}
|
|
@@ -5237,7 +6088,7 @@ async function updateDataSource(id, options, cmd) {
|
|
|
5237
6088
|
const api = createApiClient();
|
|
5238
6089
|
const ds = await api.storage.updateDataSource(id, request);
|
|
5239
6090
|
if (outputFormat === "human") {
|
|
5240
|
-
console.log(
|
|
6091
|
+
console.log(chalk27.green(`\u2713 Updated data source ${ds.id}`));
|
|
5241
6092
|
} else {
|
|
5242
6093
|
format(ds, { format: outputFormat });
|
|
5243
6094
|
}
|
|
@@ -5245,45 +6096,45 @@ async function updateDataSource(id, options, cmd) {
|
|
|
5245
6096
|
async function deleteDataSource(id) {
|
|
5246
6097
|
const api = createApiClient();
|
|
5247
6098
|
await api.storage.deleteDataSource(id);
|
|
5248
|
-
console.log(
|
|
6099
|
+
console.log(chalk27.green(`\u2713 Deleted data source ${id}`));
|
|
5249
6100
|
}
|
|
5250
6101
|
async function refreshDataSource(id, cmd) {
|
|
5251
|
-
const outputFormat =
|
|
6102
|
+
const outputFormat = getOutputFormat16(cmd);
|
|
5252
6103
|
const api = createApiClient();
|
|
5253
6104
|
const run = await api.storage.refreshDataSource(id);
|
|
5254
6105
|
if (outputFormat === "human") {
|
|
5255
|
-
console.log(
|
|
5256
|
-
if (run.errorMessage) console.log(
|
|
6106
|
+
console.log(chalk27.green(`\u2713 Refresh queued \u2014 run ${run.runId}, status ${run.status}`));
|
|
6107
|
+
if (run.errorMessage) console.log(chalk27.red(` Error: ${run.errorMessage}`));
|
|
5257
6108
|
} else {
|
|
5258
6109
|
format(run, { format: outputFormat });
|
|
5259
6110
|
}
|
|
5260
6111
|
}
|
|
5261
6112
|
async function listRuns2(id, limit, cmd) {
|
|
5262
|
-
const outputFormat =
|
|
6113
|
+
const outputFormat = getOutputFormat16(cmd);
|
|
5263
6114
|
const api = createApiClient();
|
|
5264
6115
|
const runs = await api.storage.listDataSourceRuns(id, limit);
|
|
5265
6116
|
if (outputFormat === "human" && runs.length === 0) {
|
|
5266
|
-
console.log(
|
|
6117
|
+
console.log(chalk27.dim("No runs yet."));
|
|
5267
6118
|
return;
|
|
5268
6119
|
}
|
|
5269
6120
|
format(runs.map(runTableRow), {
|
|
5270
6121
|
format: outputFormat,
|
|
5271
|
-
columns: ["runId", "status", "startedAt", "finishedAt", "rows", "triggeredBy"]
|
|
6122
|
+
columns: ["runId", "status", "startedAt", "finishedAt", "rows", "transferred", "credits", "triggeredBy"]
|
|
5272
6123
|
});
|
|
5273
6124
|
}
|
|
5274
6125
|
async function getRun(id, runId, cmd) {
|
|
5275
|
-
const outputFormat =
|
|
6126
|
+
const outputFormat = getOutputFormat16(cmd);
|
|
5276
6127
|
const api = createApiClient();
|
|
5277
6128
|
const run = await api.storage.getDataSourceRun(id, runId);
|
|
5278
6129
|
format(run, { format: outputFormat });
|
|
5279
6130
|
}
|
|
5280
6131
|
async function listConnectorTypes(cmd) {
|
|
5281
|
-
const outputFormat =
|
|
6132
|
+
const outputFormat = getOutputFormat16(cmd);
|
|
5282
6133
|
const api = createApiClient();
|
|
5283
6134
|
const types = await api.storage.listDataSourceConnectorTypes();
|
|
5284
6135
|
if (outputFormat === "human") {
|
|
5285
6136
|
if (types.length === 0) {
|
|
5286
|
-
console.log(
|
|
6137
|
+
console.log(chalk27.dim("No connector types registered."));
|
|
5287
6138
|
return;
|
|
5288
6139
|
}
|
|
5289
6140
|
for (const t of types) console.log(t);
|
|
@@ -5300,6 +6151,13 @@ function registerDataSourcesCommands(program) {
|
|
|
5300
6151
|
handleError(error);
|
|
5301
6152
|
}
|
|
5302
6153
|
});
|
|
6154
|
+
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) => {
|
|
6155
|
+
try {
|
|
6156
|
+
await showDashboard(options.projectId, cmd);
|
|
6157
|
+
} catch (error) {
|
|
6158
|
+
handleError(error);
|
|
6159
|
+
}
|
|
6160
|
+
});
|
|
5303
6161
|
dataSources.command("get").description("Show one data source").argument("<id>", "Data source ID (UUID)").action(async (id, _options, cmd) => {
|
|
5304
6162
|
try {
|
|
5305
6163
|
await getDataSource(id, cmd);
|
|
@@ -5321,8 +6179,9 @@ function registerDataSourcesCommands(program) {
|
|
|
5321
6179
|
handleError(error);
|
|
5322
6180
|
}
|
|
5323
6181
|
});
|
|
5324
|
-
dataSources.command("delete").description("Delete a data source (existing imported rows are kept)").argument("<id>", "Data source ID").action(async (id) => {
|
|
6182
|
+
dataSources.command("delete").description("Delete a data source (existing imported rows are kept)").argument("<id>", "Data source ID").option("-y, --yes", "Skip confirmation prompt (for CI / scripted use)").action(async (id, options) => {
|
|
5325
6183
|
try {
|
|
6184
|
+
await confirmDestructive(`This will permanently delete data source "${id}".`, { yes: options.yes, resourceId: id });
|
|
5326
6185
|
await deleteDataSource(id);
|
|
5327
6186
|
} catch (error) {
|
|
5328
6187
|
handleError(error);
|
|
@@ -5358,6 +6217,261 @@ function registerDataSourcesCommands(program) {
|
|
|
5358
6217
|
});
|
|
5359
6218
|
}
|
|
5360
6219
|
|
|
6220
|
+
// src/commands/table-exporters/index.ts
|
|
6221
|
+
import chalk28 from "chalk";
|
|
6222
|
+
function getOutputFormat17(cmd) {
|
|
6223
|
+
const config = loadConfig();
|
|
6224
|
+
const globalOpts = cmd.optsWithGlobals();
|
|
6225
|
+
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
6226
|
+
}
|
|
6227
|
+
function registerTableExportersCommands(program) {
|
|
6228
|
+
const exporters = program.command("table-exporters").description("Manage user-defined exporters (UDE) \u2014 admin-only");
|
|
6229
|
+
exporters.command("list").description("List all registered user-defined exporters").action(async (_options, cmd) => {
|
|
6230
|
+
try {
|
|
6231
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
6232
|
+
const api = createApiClient();
|
|
6233
|
+
const list = await api.storage.listUserDefinedExporters();
|
|
6234
|
+
if (outputFormat === "json") {
|
|
6235
|
+
format(list, { format: outputFormat });
|
|
6236
|
+
return;
|
|
6237
|
+
}
|
|
6238
|
+
const rows = list.map((e) => ({
|
|
6239
|
+
id: e.id ?? "",
|
|
6240
|
+
name: e.name,
|
|
6241
|
+
format: e.format,
|
|
6242
|
+
extension: e.extension ?? "",
|
|
6243
|
+
mimeType: e.mimeType ?? "",
|
|
6244
|
+
priority: e.priority ?? 50,
|
|
6245
|
+
function: `${e.functionProjectId}/${e.functionEntityId}`,
|
|
6246
|
+
createdBy: e.createdBy ?? ""
|
|
6247
|
+
}));
|
|
6248
|
+
format(rows, {
|
|
6249
|
+
format: outputFormat,
|
|
6250
|
+
columns: ["id", "name", "format", "extension", "mimeType", "priority", "function", "createdBy"]
|
|
6251
|
+
});
|
|
6252
|
+
console.log(chalk28.dim(`${list.length} exporter(s)`));
|
|
6253
|
+
} catch (error) {
|
|
6254
|
+
handleError(error);
|
|
6255
|
+
}
|
|
6256
|
+
});
|
|
6257
|
+
exporters.command("get").description("Show a single user-defined exporter by id").argument("<id>", "Exporter id").action(async (id, _options, cmd) => {
|
|
6258
|
+
try {
|
|
6259
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
6260
|
+
const api = createApiClient();
|
|
6261
|
+
const list = await api.storage.listUserDefinedExporters();
|
|
6262
|
+
const exporter = list.find((e) => e.id === id);
|
|
6263
|
+
if (!exporter) {
|
|
6264
|
+
console.error(chalk28.red(`No exporter with id="${id}".`));
|
|
6265
|
+
process.exit(1);
|
|
6266
|
+
}
|
|
6267
|
+
format(exporter, { format: outputFormat });
|
|
6268
|
+
} catch (error) {
|
|
6269
|
+
handleError(error);
|
|
6270
|
+
}
|
|
6271
|
+
});
|
|
6272
|
+
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) => {
|
|
6273
|
+
try {
|
|
6274
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
6275
|
+
const api = createApiClient();
|
|
6276
|
+
const payload = {
|
|
6277
|
+
name: options.name,
|
|
6278
|
+
description: options.description,
|
|
6279
|
+
format: options.format,
|
|
6280
|
+
extension: options.extension,
|
|
6281
|
+
mimeType: options.mimeType,
|
|
6282
|
+
functionProjectId: options.functionProject,
|
|
6283
|
+
functionProjectBranch: options.functionProjectBranch,
|
|
6284
|
+
functionEntityId: options.functionEntity,
|
|
6285
|
+
functionEntityBranch: options.functionEntityBranch,
|
|
6286
|
+
priority: Number(options.priority)
|
|
6287
|
+
};
|
|
6288
|
+
const created = await api.storage.registerUserDefinedExporter(payload);
|
|
6289
|
+
if (outputFormat === "json") {
|
|
6290
|
+
format(created, { format: outputFormat });
|
|
6291
|
+
return;
|
|
6292
|
+
}
|
|
6293
|
+
console.log(chalk28.green(`Registered exporter "${created.name}" (id=${created.id}, format=${created.format})`));
|
|
6294
|
+
} catch (error) {
|
|
6295
|
+
handleError(error);
|
|
6296
|
+
}
|
|
6297
|
+
});
|
|
6298
|
+
exporters.command("delete").description("Delete a user-defined exporter").argument("<id>", "Exporter id").action(async (id) => {
|
|
6299
|
+
try {
|
|
6300
|
+
const api = createApiClient();
|
|
6301
|
+
await api.storage.deleteUserDefinedExporter(id);
|
|
6302
|
+
console.log(chalk28.green(`Deleted exporter id=${id}`));
|
|
6303
|
+
} catch (error) {
|
|
6304
|
+
handleError(error);
|
|
6305
|
+
}
|
|
6306
|
+
});
|
|
6307
|
+
}
|
|
6308
|
+
|
|
6309
|
+
// src/commands/skeleton/index.ts
|
|
6310
|
+
import chalk29 from "chalk";
|
|
6311
|
+
import * as fs9 from "fs";
|
|
6312
|
+
function getOutputFormat18(cmd) {
|
|
6313
|
+
const config = loadConfig();
|
|
6314
|
+
const globalOpts = cmd.optsWithGlobals();
|
|
6315
|
+
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
6316
|
+
}
|
|
6317
|
+
function resolveProjectId(localOption, cmd) {
|
|
6318
|
+
if (localOption) return localOption;
|
|
6319
|
+
const globalOpts = cmd.optsWithGlobals();
|
|
6320
|
+
if (globalOpts.project) return globalOpts.project;
|
|
6321
|
+
const config = loadConfig();
|
|
6322
|
+
if (config.defaults.project) return config.defaults.project;
|
|
6323
|
+
throw new Error(
|
|
6324
|
+
"No project specified. Pass --project <id>, set the global --project flag, or run `diafunc config defaults project <id>`."
|
|
6325
|
+
);
|
|
6326
|
+
}
|
|
6327
|
+
function resolveTemplate(raw) {
|
|
6328
|
+
if (raw.startsWith("@@")) {
|
|
6329
|
+
return raw.substring(1);
|
|
6330
|
+
}
|
|
6331
|
+
if (raw.startsWith("@")) {
|
|
6332
|
+
const file = raw.substring(1);
|
|
6333
|
+
if (!file) {
|
|
6334
|
+
throw new Error("--template @ requires a filename after the @, e.g. --template @template.txt");
|
|
6335
|
+
}
|
|
6336
|
+
if (!fs9.existsSync(file)) {
|
|
6337
|
+
throw new Error(`Template file not found: ${file}`);
|
|
6338
|
+
}
|
|
6339
|
+
return fs9.readFileSync(file, "utf-8").trim();
|
|
6340
|
+
}
|
|
6341
|
+
return raw;
|
|
6342
|
+
}
|
|
6343
|
+
function parseWeight(raw) {
|
|
6344
|
+
if (raw === void 0) return null;
|
|
6345
|
+
const value = Number(raw);
|
|
6346
|
+
if (!Number.isFinite(value) || value <= 0) {
|
|
6347
|
+
throw new Error(`Invalid --weight "${raw}" \u2014 must be a positive number.`);
|
|
6348
|
+
}
|
|
6349
|
+
return value;
|
|
6350
|
+
}
|
|
6351
|
+
function skeletonTableRow(s) {
|
|
6352
|
+
return {
|
|
6353
|
+
id: s.id,
|
|
6354
|
+
name: s.name,
|
|
6355
|
+
template: s.template,
|
|
6356
|
+
paramCount: String(s.paramCount),
|
|
6357
|
+
weight: s.weight.toFixed(2),
|
|
6358
|
+
createdAt: s.createdAt ?? "\u2014"
|
|
6359
|
+
};
|
|
6360
|
+
}
|
|
6361
|
+
async function createSkeleton(options, cmd) {
|
|
6362
|
+
const outputFormat = getOutputFormat18(cmd);
|
|
6363
|
+
const projectId = resolveProjectId(options.project, cmd);
|
|
6364
|
+
const template = resolveTemplate(options.template);
|
|
6365
|
+
const weight = parseWeight(options.weight);
|
|
6366
|
+
const request = {
|
|
6367
|
+
projectId,
|
|
6368
|
+
projectBranch: options.branch,
|
|
6369
|
+
name: options.name,
|
|
6370
|
+
template,
|
|
6371
|
+
weight
|
|
6372
|
+
};
|
|
6373
|
+
const api = createApiClient();
|
|
6374
|
+
const skeleton = await api.storage.createSkeleton(request);
|
|
6375
|
+
if (outputFormat === "human") {
|
|
6376
|
+
console.log(chalk29.green(`\u2713 Created skeleton ${skeleton.id}`));
|
|
6377
|
+
console.log(chalk29.dim(` name: ${skeleton.name}`));
|
|
6378
|
+
console.log(chalk29.dim(` template: ${skeleton.template}`));
|
|
6379
|
+
console.log(chalk29.dim(` paramCount: ${skeleton.paramCount}`));
|
|
6380
|
+
console.log(chalk29.dim(` weight: ${skeleton.weight}`));
|
|
6381
|
+
} else {
|
|
6382
|
+
format(skeleton, { format: outputFormat });
|
|
6383
|
+
}
|
|
6384
|
+
}
|
|
6385
|
+
async function listSkeletons(localProject, cmd) {
|
|
6386
|
+
const outputFormat = getOutputFormat18(cmd);
|
|
6387
|
+
const projectId = resolveProjectId(localProject, cmd);
|
|
6388
|
+
const api = createApiClient();
|
|
6389
|
+
const skeletons = await api.storage.listSkeletons(projectId);
|
|
6390
|
+
if (outputFormat === "human" && skeletons.length === 0) {
|
|
6391
|
+
console.log(chalk29.dim(`No skeletons in project ${projectId}.`));
|
|
6392
|
+
return;
|
|
6393
|
+
}
|
|
6394
|
+
format(skeletons.map(skeletonTableRow), {
|
|
6395
|
+
format: outputFormat,
|
|
6396
|
+
columns: ["id", "name", "template", "paramCount", "weight", "createdAt"]
|
|
6397
|
+
});
|
|
6398
|
+
}
|
|
6399
|
+
async function getSkeleton(id, cmd) {
|
|
6400
|
+
const outputFormat = getOutputFormat18(cmd);
|
|
6401
|
+
const api = createApiClient();
|
|
6402
|
+
const skeleton = await api.storage.getSkeleton(id);
|
|
6403
|
+
format(skeleton, { format: outputFormat });
|
|
6404
|
+
}
|
|
6405
|
+
async function updateSkeleton(id, options, cmd) {
|
|
6406
|
+
const outputFormat = getOutputFormat18(cmd);
|
|
6407
|
+
if (options.name === void 0 && options.template === void 0 && options.weight === void 0) {
|
|
6408
|
+
throw new Error("Provide at least one of --name, --template, --weight.");
|
|
6409
|
+
}
|
|
6410
|
+
const request = {
|
|
6411
|
+
name: options.name ?? null,
|
|
6412
|
+
template: options.template !== void 0 ? resolveTemplate(options.template) : null,
|
|
6413
|
+
weight: parseWeight(options.weight)
|
|
6414
|
+
};
|
|
6415
|
+
const api = createApiClient();
|
|
6416
|
+
const skeleton = await api.storage.updateSkeleton(id, request);
|
|
6417
|
+
if (outputFormat === "human") {
|
|
6418
|
+
console.log(chalk29.green(`\u2713 Updated skeleton ${skeleton.id}`));
|
|
6419
|
+
console.log(chalk29.dim(` name: ${skeleton.name}`));
|
|
6420
|
+
console.log(chalk29.dim(` template: ${skeleton.template}`));
|
|
6421
|
+
console.log(chalk29.dim(` paramCount: ${skeleton.paramCount}`));
|
|
6422
|
+
console.log(chalk29.dim(` weight: ${skeleton.weight}`));
|
|
6423
|
+
} else {
|
|
6424
|
+
format(skeleton, { format: outputFormat });
|
|
6425
|
+
}
|
|
6426
|
+
}
|
|
6427
|
+
async function deleteSkeleton(id) {
|
|
6428
|
+
const api = createApiClient();
|
|
6429
|
+
await api.storage.deleteSkeleton(id);
|
|
6430
|
+
console.log(chalk29.green(`\u2713 Deleted skeleton ${id}`));
|
|
6431
|
+
}
|
|
6432
|
+
function registerSkeletonCommands(program) {
|
|
6433
|
+
const skeleton = program.command("skeleton").description("Manage user-provided skeleton templates (project-scoped, capped at 100/project)");
|
|
6434
|
+
skeleton.command("create").description("Create a skeleton. Parse errors from the engine are surfaced as stderr.").requiredOption("--name <name>", "Display name").requiredOption(
|
|
6435
|
+
"--template <expr>",
|
|
6436
|
+
'Skeleton template expression (e.g. "?*x+?"). Use "@file.txt" to read from a file; "@@\u2026" escapes a literal leading @.'
|
|
6437
|
+
).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) => {
|
|
6438
|
+
try {
|
|
6439
|
+
await createSkeleton(options, cmd);
|
|
6440
|
+
} catch (error) {
|
|
6441
|
+
handleError(error);
|
|
6442
|
+
}
|
|
6443
|
+
});
|
|
6444
|
+
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) => {
|
|
6445
|
+
try {
|
|
6446
|
+
await listSkeletons(options.project, cmd);
|
|
6447
|
+
} catch (error) {
|
|
6448
|
+
handleError(error);
|
|
6449
|
+
}
|
|
6450
|
+
});
|
|
6451
|
+
skeleton.command("get").description("Show one skeleton").argument("<id>", "Skeleton ID (UUID)").action(async (id, _options, cmd) => {
|
|
6452
|
+
try {
|
|
6453
|
+
await getSkeleton(id, cmd);
|
|
6454
|
+
} catch (error) {
|
|
6455
|
+
handleError(error);
|
|
6456
|
+
}
|
|
6457
|
+
});
|
|
6458
|
+
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) => {
|
|
6459
|
+
try {
|
|
6460
|
+
await updateSkeleton(id, options, cmd);
|
|
6461
|
+
} catch (error) {
|
|
6462
|
+
handleError(error);
|
|
6463
|
+
}
|
|
6464
|
+
});
|
|
6465
|
+
skeleton.command("delete").description("Delete a skeleton").argument("<id>", "Skeleton ID").option("-y, --yes", "Skip confirmation prompt (for CI / scripted use)").action(async (id, options) => {
|
|
6466
|
+
try {
|
|
6467
|
+
await confirmDestructive(`This will permanently delete skeleton "${id}".`, { yes: options.yes, resourceId: id });
|
|
6468
|
+
await deleteSkeleton(id);
|
|
6469
|
+
} catch (error) {
|
|
6470
|
+
handleError(error);
|
|
6471
|
+
}
|
|
6472
|
+
});
|
|
6473
|
+
}
|
|
6474
|
+
|
|
5361
6475
|
// src/commands/completion/index.ts
|
|
5362
6476
|
var BASH_COMPLETION = `#!/bin/bash
|
|
5363
6477
|
_diafunc_completions() {
|
|
@@ -5612,7 +6726,7 @@ function registerCompletionCommand(program) {
|
|
|
5612
6726
|
}
|
|
5613
6727
|
|
|
5614
6728
|
// src/commands/whoami/index.ts
|
|
5615
|
-
import
|
|
6729
|
+
import chalk30 from "chalk";
|
|
5616
6730
|
function registerWhoamiCommand(program) {
|
|
5617
6731
|
program.command("whoami").description("Show the currently authenticated user").action(async (_options, cmd) => {
|
|
5618
6732
|
try {
|
|
@@ -5622,8 +6736,8 @@ function registerWhoamiCommand(program) {
|
|
|
5622
6736
|
const api = createApiClient();
|
|
5623
6737
|
const user = await api.admin.getMyUser();
|
|
5624
6738
|
if (outputFormat === "human") {
|
|
5625
|
-
console.log(
|
|
5626
|
-
console.log(
|
|
6739
|
+
console.log(chalk30.bold(user.name) + chalk30.dim(` <${user.email}>`));
|
|
6740
|
+
console.log(chalk30.dim(` Role: ${user.role} \xB7 Remaining credits: ${user.remainingCredits} \xB7 Profile: ${config.currentProfile}`));
|
|
5627
6741
|
} else {
|
|
5628
6742
|
format(user, { format: outputFormat });
|
|
5629
6743
|
}
|
|
@@ -5634,8 +6748,8 @@ function registerWhoamiCommand(program) {
|
|
|
5634
6748
|
}
|
|
5635
6749
|
|
|
5636
6750
|
// src/commands/utilization/index.ts
|
|
5637
|
-
import
|
|
5638
|
-
function
|
|
6751
|
+
import chalk31 from "chalk";
|
|
6752
|
+
function getOutputFormat19(cmd) {
|
|
5639
6753
|
const config = loadConfig();
|
|
5640
6754
|
const globalOpts = cmd.optsWithGlobals();
|
|
5641
6755
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -5643,27 +6757,27 @@ function getOutputFormat16(cmd) {
|
|
|
5643
6757
|
function printUtilizationHuman(u, label) {
|
|
5644
6758
|
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")}`;
|
|
5645
6759
|
if (label) {
|
|
5646
|
-
console.log(
|
|
6760
|
+
console.log(chalk31.bold(label) + " " + chalk31.dim(when));
|
|
5647
6761
|
} else {
|
|
5648
|
-
console.log(
|
|
6762
|
+
console.log(chalk31.bold(when));
|
|
5649
6763
|
}
|
|
5650
6764
|
if (u.types.length === 0) {
|
|
5651
|
-
console.log(
|
|
6765
|
+
console.log(chalk31.dim(" (no usage)"));
|
|
5652
6766
|
return;
|
|
5653
6767
|
}
|
|
5654
6768
|
for (const t of u.types) {
|
|
5655
6769
|
console.log(
|
|
5656
|
-
` ${t.type.padEnd(24)} ${
|
|
6770
|
+
` ${t.type.padEnd(24)} ${chalk31.cyan(String(t.quantity).padStart(10))} ${chalk31.dim("credits:")} ${t.credits.toFixed(2)}`
|
|
5657
6771
|
);
|
|
5658
6772
|
}
|
|
5659
6773
|
const total = u.totalCredits ?? u.types.reduce((s, t) => s + t.credits, 0);
|
|
5660
|
-
console.log(
|
|
6774
|
+
console.log(chalk31.bold(` Total credits: ${total.toFixed(2)}`));
|
|
5661
6775
|
}
|
|
5662
6776
|
function registerUtilizationCommand(program) {
|
|
5663
6777
|
const util = program.command("utilization").description("Show credit utilization");
|
|
5664
6778
|
util.command("actual", { isDefault: true }).description("Show current utilization (default subcommand)").action(async (_options, cmd) => {
|
|
5665
6779
|
try {
|
|
5666
|
-
const outputFormat =
|
|
6780
|
+
const outputFormat = getOutputFormat19(cmd);
|
|
5667
6781
|
const api = createApiClient();
|
|
5668
6782
|
const utilization = await api.admin.getActualUtilization();
|
|
5669
6783
|
if (outputFormat === "human") {
|
|
@@ -5677,12 +6791,12 @@ function registerUtilizationCommand(program) {
|
|
|
5677
6791
|
});
|
|
5678
6792
|
util.command("history").description("Show utilization history").action(async (_options, cmd) => {
|
|
5679
6793
|
try {
|
|
5680
|
-
const outputFormat =
|
|
6794
|
+
const outputFormat = getOutputFormat19(cmd);
|
|
5681
6795
|
const api = createApiClient();
|
|
5682
6796
|
const history = await api.admin.getUtilizationHistory();
|
|
5683
6797
|
if (outputFormat === "human") {
|
|
5684
6798
|
if (history.length === 0) {
|
|
5685
|
-
console.log(
|
|
6799
|
+
console.log(chalk31.dim("No usage recorded."));
|
|
5686
6800
|
return;
|
|
5687
6801
|
}
|
|
5688
6802
|
for (const u of history) {
|
|
@@ -5699,13 +6813,13 @@ function registerUtilizationCommand(program) {
|
|
|
5699
6813
|
}
|
|
5700
6814
|
|
|
5701
6815
|
// src/commands/entity-branch/index.ts
|
|
5702
|
-
import
|
|
5703
|
-
function
|
|
6816
|
+
import chalk32 from "chalk";
|
|
6817
|
+
function getOutputFormat20(cmd) {
|
|
5704
6818
|
const config = loadConfig();
|
|
5705
6819
|
const globalOpts = cmd.optsWithGlobals();
|
|
5706
6820
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
5707
6821
|
}
|
|
5708
|
-
function
|
|
6822
|
+
function getOverrides11(cmd) {
|
|
5709
6823
|
const opts = cmd.optsWithGlobals();
|
|
5710
6824
|
return { project: opts.project, branch: opts.branch };
|
|
5711
6825
|
}
|
|
@@ -5713,8 +6827,8 @@ function registerEntityBranchCommands(program) {
|
|
|
5713
6827
|
const eb = program.command("entity-branch").description("Manage entity branches (parallel versions of a single entity)");
|
|
5714
6828
|
eb.command("list").description("List branches of an entity").argument("<ref>", "Entity reference (projectId/branch/entityId)").action(async (ref, _options, cmd) => {
|
|
5715
6829
|
try {
|
|
5716
|
-
const outputFormat =
|
|
5717
|
-
const overrides =
|
|
6830
|
+
const outputFormat = getOutputFormat20(cmd);
|
|
6831
|
+
const overrides = getOverrides11(cmd);
|
|
5718
6832
|
const resolved = parseEntityReference(ref, overrides);
|
|
5719
6833
|
const api = createApiClient();
|
|
5720
6834
|
const branches = await api.storage.getEntityBranches(
|
|
@@ -5733,7 +6847,7 @@ function registerEntityBranchCommands(program) {
|
|
|
5733
6847
|
});
|
|
5734
6848
|
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) => {
|
|
5735
6849
|
try {
|
|
5736
|
-
const overrides =
|
|
6850
|
+
const overrides = getOverrides11(cmd);
|
|
5737
6851
|
const resolved = parseEntityReference(ref, overrides);
|
|
5738
6852
|
const api = createApiClient();
|
|
5739
6853
|
await api.storage.createEntityBranch({
|
|
@@ -5743,7 +6857,7 @@ function registerEntityBranchCommands(program) {
|
|
|
5743
6857
|
sourceEntityBranch: resolved.entityBranch,
|
|
5744
6858
|
targetEntityBranch: targetBranch
|
|
5745
6859
|
});
|
|
5746
|
-
console.log(
|
|
6860
|
+
console.log(chalk32.green(`Entity branch "${targetBranch}" created from "${resolved.entityBranch}".`));
|
|
5747
6861
|
} catch (error) {
|
|
5748
6862
|
handleError(error);
|
|
5749
6863
|
}
|
|
@@ -5751,7 +6865,7 @@ function registerEntityBranchCommands(program) {
|
|
|
5751
6865
|
}
|
|
5752
6866
|
|
|
5753
6867
|
// src/commands/subscription/index.ts
|
|
5754
|
-
function
|
|
6868
|
+
function getOutputFormat21(cmd) {
|
|
5755
6869
|
const config = loadConfig();
|
|
5756
6870
|
const globalOpts = cmd.optsWithGlobals();
|
|
5757
6871
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -5762,7 +6876,7 @@ function registerSubscriptionCommand(program) {
|
|
|
5762
6876
|
try {
|
|
5763
6877
|
const api = createApiClient();
|
|
5764
6878
|
const s = await api.admin.getCurrentSubscription();
|
|
5765
|
-
format(s, { format:
|
|
6879
|
+
format(s, { format: getOutputFormat21(cmd) });
|
|
5766
6880
|
} catch (error) {
|
|
5767
6881
|
handleError(error);
|
|
5768
6882
|
}
|
|
@@ -5771,7 +6885,7 @@ function registerSubscriptionCommand(program) {
|
|
|
5771
6885
|
try {
|
|
5772
6886
|
const api = createApiClient();
|
|
5773
6887
|
const s = await api.admin.getNextSubscription();
|
|
5774
|
-
format(s, { format:
|
|
6888
|
+
format(s, { format: getOutputFormat21(cmd) });
|
|
5775
6889
|
} catch (error) {
|
|
5776
6890
|
handleError(error);
|
|
5777
6891
|
}
|
|
@@ -5780,7 +6894,7 @@ function registerSubscriptionCommand(program) {
|
|
|
5780
6894
|
try {
|
|
5781
6895
|
const api = createApiClient();
|
|
5782
6896
|
const plans = await api.admin.getSubscriptionPlans(subscriptionToken);
|
|
5783
|
-
format(plans, { format:
|
|
6897
|
+
format(plans, { format: getOutputFormat21(cmd) });
|
|
5784
6898
|
} catch (error) {
|
|
5785
6899
|
handleError(error);
|
|
5786
6900
|
}
|
|
@@ -5788,9 +6902,9 @@ function registerSubscriptionCommand(program) {
|
|
|
5788
6902
|
}
|
|
5789
6903
|
|
|
5790
6904
|
// src/commands/invoice/index.ts
|
|
5791
|
-
import
|
|
5792
|
-
import * as
|
|
5793
|
-
function
|
|
6905
|
+
import chalk33 from "chalk";
|
|
6906
|
+
import * as fs10 from "fs";
|
|
6907
|
+
function getOutputFormat22(cmd) {
|
|
5794
6908
|
const config = loadConfig();
|
|
5795
6909
|
const globalOpts = cmd.optsWithGlobals();
|
|
5796
6910
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -5802,7 +6916,7 @@ function registerInvoiceCommand(program) {
|
|
|
5802
6916
|
const api = createApiClient();
|
|
5803
6917
|
const invoices = await api.admin.getInvoices();
|
|
5804
6918
|
format(invoices, {
|
|
5805
|
-
format:
|
|
6919
|
+
format: getOutputFormat22(cmd),
|
|
5806
6920
|
columns: ["invoiceNumber", "issued", "periodFrom", "periodTo", "total", "status"]
|
|
5807
6921
|
});
|
|
5808
6922
|
} catch (error) {
|
|
@@ -5815,8 +6929,8 @@ function registerInvoiceCommand(program) {
|
|
|
5815
6929
|
const response = await api.admin.downloadInvoice(invoiceNumber, fileName);
|
|
5816
6930
|
const buffer = Buffer.from(await response.arrayBuffer());
|
|
5817
6931
|
const outPath = options.out ?? fileName;
|
|
5818
|
-
|
|
5819
|
-
console.log(
|
|
6932
|
+
fs10.writeFileSync(outPath, buffer);
|
|
6933
|
+
console.log(chalk33.green(`Invoice saved to ${outPath}`));
|
|
5820
6934
|
} catch (error) {
|
|
5821
6935
|
handleError(error);
|
|
5822
6936
|
}
|
|
@@ -5824,10 +6938,10 @@ function registerInvoiceCommand(program) {
|
|
|
5824
6938
|
}
|
|
5825
6939
|
|
|
5826
6940
|
// src/commands/shell/index.ts
|
|
5827
|
-
import
|
|
5828
|
-
import * as
|
|
6941
|
+
import chalk34 from "chalk";
|
|
6942
|
+
import * as fs11 from "fs";
|
|
5829
6943
|
import * as os3 from "os";
|
|
5830
|
-
import * as
|
|
6944
|
+
import * as path8 from "path";
|
|
5831
6945
|
import { spawn as spawn3 } from "child_process";
|
|
5832
6946
|
import { randomUUID as randomUUID3 } from "crypto";
|
|
5833
6947
|
function extensionFor2(language) {
|
|
@@ -5840,16 +6954,16 @@ function extensionFor2(language) {
|
|
|
5840
6954
|
return "txt";
|
|
5841
6955
|
}
|
|
5842
6956
|
async function openInEditor(initial, ext) {
|
|
5843
|
-
const tmpFile =
|
|
5844
|
-
|
|
6957
|
+
const tmpFile = path8.join(os3.tmpdir(), `diafunc-shell-${randomUUID3()}.${ext}`);
|
|
6958
|
+
fs11.writeFileSync(tmpFile, initial);
|
|
5845
6959
|
const editor = process.env.VISUAL ?? process.env.EDITOR ?? "vi";
|
|
5846
6960
|
await new Promise((resolve, reject) => {
|
|
5847
6961
|
const child = spawn3(editor, [tmpFile], { stdio: "inherit" });
|
|
5848
6962
|
child.on("exit", (code) => code === 0 ? resolve() : reject(new Error(`Editor exited with ${code}`)));
|
|
5849
6963
|
child.on("error", reject);
|
|
5850
6964
|
});
|
|
5851
|
-
const content =
|
|
5852
|
-
|
|
6965
|
+
const content = fs11.readFileSync(tmpFile, "utf-8");
|
|
6966
|
+
fs11.unlinkSync(tmpFile);
|
|
5853
6967
|
return content;
|
|
5854
6968
|
}
|
|
5855
6969
|
function utcNowParts() {
|
|
@@ -5890,21 +7004,21 @@ async function evaluate(api, fnRef, language, sourceCode) {
|
|
|
5890
7004
|
}, false);
|
|
5891
7005
|
if (result.outputs?.length) {
|
|
5892
7006
|
for (const out of result.outputs) {
|
|
5893
|
-
console.log(
|
|
7007
|
+
console.log(chalk34.dim(` [${out.type}]`) + " " + out.output);
|
|
5894
7008
|
}
|
|
5895
7009
|
}
|
|
5896
7010
|
if (result.successful) {
|
|
5897
7011
|
if (result.result) {
|
|
5898
|
-
console.log(
|
|
7012
|
+
console.log(chalk34.green("=> ") + result.result);
|
|
5899
7013
|
} else {
|
|
5900
|
-
console.log(
|
|
7014
|
+
console.log(chalk34.dim("=> (no value)"));
|
|
5901
7015
|
}
|
|
5902
7016
|
const duration = result.completed - result.started;
|
|
5903
|
-
console.log(
|
|
7017
|
+
console.log(chalk34.dim(` [${duration}ms \xB7 ${evaluationId}]`));
|
|
5904
7018
|
} else {
|
|
5905
|
-
console.log(
|
|
7019
|
+
console.log(chalk34.red("error: ") + result.error);
|
|
5906
7020
|
if (result.lineNumber > 0) {
|
|
5907
|
-
console.log(
|
|
7021
|
+
console.log(chalk34.dim(` at line ${result.lineNumber}, col ${result.columnNumber}`));
|
|
5908
7022
|
}
|
|
5909
7023
|
}
|
|
5910
7024
|
}
|
|
@@ -5912,9 +7026,9 @@ function registerShellCommand(program) {
|
|
|
5912
7026
|
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) => {
|
|
5913
7027
|
try {
|
|
5914
7028
|
if (!options.function) {
|
|
5915
|
-
console.error(
|
|
5916
|
-
console.error(
|
|
5917
|
-
console.error(
|
|
7029
|
+
console.error(chalk34.red("Missing --function <ref>."));
|
|
7030
|
+
console.error(chalk34.dim("Pass an existing or new function entity reference to use as the shell target."));
|
|
7031
|
+
console.error(chalk34.dim("Example: diafunc shell --function my-project/main/scratch/main --language JavaScript"));
|
|
5918
7032
|
process.exit(1);
|
|
5919
7033
|
}
|
|
5920
7034
|
const config = loadConfig();
|
|
@@ -5925,18 +7039,18 @@ function registerShellCommand(program) {
|
|
|
5925
7039
|
});
|
|
5926
7040
|
const api = createApiClient();
|
|
5927
7041
|
const { input: promptInput } = await import("@inquirer/prompts");
|
|
5928
|
-
const { getUpdateNotice } = await import("./update-check-
|
|
5929
|
-
console.log(
|
|
5930
|
-
console.log(
|
|
5931
|
-
console.log(
|
|
7042
|
+
const { getUpdateNotice } = await import("./update-check-2X2AIL52.js");
|
|
7043
|
+
console.log(chalk34.bold("Diafunc shell") + chalk34.dim(` \xB7 function ${fnRef.entityId} \xB7 ${options.language}`));
|
|
7044
|
+
console.log(chalk34.dim(`Endpoint: ${config.profiles[config.currentProfile]?.endpoint}`));
|
|
7045
|
+
console.log(chalk34.dim("Commands: /edit (multi-line in $EDITOR), /lang <name>, /file <path>, /help, /quit"));
|
|
5932
7046
|
const notice = await getUpdateNotice();
|
|
5933
|
-
if (notice) console.log(
|
|
7047
|
+
if (notice) console.log(chalk34.dim(notice));
|
|
5934
7048
|
console.log();
|
|
5935
7049
|
let language = options.language;
|
|
5936
7050
|
for (; ; ) {
|
|
5937
7051
|
let line;
|
|
5938
7052
|
try {
|
|
5939
|
-
line = await promptInput({ message:
|
|
7053
|
+
line = await promptInput({ message: chalk34.cyan.bold(`${language} >`) });
|
|
5940
7054
|
} catch {
|
|
5941
7055
|
console.log();
|
|
5942
7056
|
return;
|
|
@@ -5954,54 +7068,54 @@ function registerShellCommand(program) {
|
|
|
5954
7068
|
case "help":
|
|
5955
7069
|
case "h":
|
|
5956
7070
|
case "?":
|
|
5957
|
-
console.log(
|
|
5958
|
-
console.log(
|
|
5959
|
-
console.log(
|
|
5960
|
-
console.log(
|
|
7071
|
+
console.log(chalk34.dim(" /edit open $EDITOR for multi-line code"));
|
|
7072
|
+
console.log(chalk34.dim(" /file <path> evaluate the contents of a file"));
|
|
7073
|
+
console.log(chalk34.dim(" /lang <name> switch language (Java, JavaScript, Kotlin, Python, Scala)"));
|
|
7074
|
+
console.log(chalk34.dim(" /quit exit the shell"));
|
|
5961
7075
|
continue;
|
|
5962
7076
|
case "lang":
|
|
5963
7077
|
if (arg) language = arg;
|
|
5964
|
-
console.log(
|
|
7078
|
+
console.log(chalk34.dim(`Language: ${language}`));
|
|
5965
7079
|
continue;
|
|
5966
7080
|
case "edit": {
|
|
5967
7081
|
const sourceCode = await openInEditor("", extensionFor2(language));
|
|
5968
7082
|
if (!sourceCode.trim()) {
|
|
5969
|
-
console.log(
|
|
7083
|
+
console.log(chalk34.dim("(empty \u2014 not evaluated)"));
|
|
5970
7084
|
continue;
|
|
5971
7085
|
}
|
|
5972
7086
|
try {
|
|
5973
7087
|
await evaluate(api, fnRef, language, sourceCode);
|
|
5974
7088
|
} catch (e) {
|
|
5975
|
-
console.error(
|
|
7089
|
+
console.error(chalk34.red(e.message));
|
|
5976
7090
|
}
|
|
5977
7091
|
continue;
|
|
5978
7092
|
}
|
|
5979
7093
|
case "file": {
|
|
5980
7094
|
if (!arg) {
|
|
5981
|
-
console.log(
|
|
7095
|
+
console.log(chalk34.dim("usage: /file <path>"));
|
|
5982
7096
|
continue;
|
|
5983
7097
|
}
|
|
5984
|
-
if (!
|
|
5985
|
-
console.log(
|
|
7098
|
+
if (!fs11.existsSync(arg)) {
|
|
7099
|
+
console.log(chalk34.red(`file not found: ${arg}`));
|
|
5986
7100
|
continue;
|
|
5987
7101
|
}
|
|
5988
|
-
const sourceCode =
|
|
7102
|
+
const sourceCode = fs11.readFileSync(arg, "utf-8");
|
|
5989
7103
|
try {
|
|
5990
7104
|
await evaluate(api, fnRef, language, sourceCode);
|
|
5991
7105
|
} catch (e) {
|
|
5992
|
-
console.error(
|
|
7106
|
+
console.error(chalk34.red(e.message));
|
|
5993
7107
|
}
|
|
5994
7108
|
continue;
|
|
5995
7109
|
}
|
|
5996
7110
|
default:
|
|
5997
|
-
console.log(
|
|
7111
|
+
console.log(chalk34.dim(`Unknown command: /${cmd2}. Try /help.`));
|
|
5998
7112
|
continue;
|
|
5999
7113
|
}
|
|
6000
7114
|
}
|
|
6001
7115
|
try {
|
|
6002
7116
|
await evaluate(api, fnRef, language, trimmed);
|
|
6003
7117
|
} catch (e) {
|
|
6004
|
-
console.error(
|
|
7118
|
+
console.error(chalk34.red(e.message));
|
|
6005
7119
|
}
|
|
6006
7120
|
}
|
|
6007
7121
|
} catch (error) {
|
|
@@ -6011,19 +7125,19 @@ function registerShellCommand(program) {
|
|
|
6011
7125
|
}
|
|
6012
7126
|
|
|
6013
7127
|
// src/commands/update/index.ts
|
|
6014
|
-
import
|
|
6015
|
-
import * as
|
|
7128
|
+
import chalk35 from "chalk";
|
|
7129
|
+
import * as path9 from "path";
|
|
6016
7130
|
import { spawn as spawn4 } from "child_process";
|
|
6017
7131
|
|
|
6018
7132
|
// src/util/install-method.ts
|
|
6019
|
-
import * as
|
|
7133
|
+
import * as fs12 from "fs";
|
|
6020
7134
|
function detectInstall() {
|
|
6021
7135
|
const exec = process.execPath;
|
|
6022
7136
|
const exe = exec.replace(/\\/g, "/").toLowerCase();
|
|
6023
7137
|
const isNode = exe.endsWith("/node") || exe.endsWith("/node.exe");
|
|
6024
7138
|
return {
|
|
6025
7139
|
method: isNode ? "npm" : "binary",
|
|
6026
|
-
binaryPath: isNode ? exec :
|
|
7140
|
+
binaryPath: isNode ? exec : fs12.realpathSync(exec)
|
|
6027
7141
|
};
|
|
6028
7142
|
}
|
|
6029
7143
|
|
|
@@ -6057,17 +7171,17 @@ function registerUpdateCommand(program) {
|
|
|
6057
7171
|
const install = detectInstall();
|
|
6058
7172
|
const latest = await fetchLatestVersion();
|
|
6059
7173
|
if (latest === package_default.version) {
|
|
6060
|
-
console.log(
|
|
7174
|
+
console.log(chalk35.dim(`diafunc is already at the latest version (${package_default.version}).`));
|
|
6061
7175
|
return;
|
|
6062
7176
|
}
|
|
6063
|
-
console.log(
|
|
7177
|
+
console.log(chalk35.dim(`Current: ${package_default.version} \u2192 Available: ${latest}`));
|
|
6064
7178
|
if (install.method === "npm") {
|
|
6065
7179
|
console.log();
|
|
6066
7180
|
console.log("Installed via npm. Upgrade with:");
|
|
6067
|
-
console.log(
|
|
7181
|
+
console.log(chalk35.bold(` npm install -g @diafunc/cli@${latest}`));
|
|
6068
7182
|
return;
|
|
6069
7183
|
}
|
|
6070
|
-
const installDir =
|
|
7184
|
+
const installDir = path9.dirname(install.binaryPath);
|
|
6071
7185
|
console.log(`Installing diafunc ${latest} to ${installDir}...`);
|
|
6072
7186
|
console.log();
|
|
6073
7187
|
await runInstaller(installDir);
|
|
@@ -6078,23 +7192,23 @@ function registerUpdateCommand(program) {
|
|
|
6078
7192
|
}
|
|
6079
7193
|
|
|
6080
7194
|
// src/commands/uninstall/index.ts
|
|
6081
|
-
import
|
|
7195
|
+
import chalk36 from "chalk";
|
|
6082
7196
|
import { spawn as spawn5 } from "child_process";
|
|
6083
|
-
import * as
|
|
7197
|
+
import * as fs13 from "fs";
|
|
6084
7198
|
import * as os4 from "os";
|
|
6085
|
-
import * as
|
|
7199
|
+
import * as path10 from "path";
|
|
6086
7200
|
function registerUninstallCommand(program) {
|
|
6087
7201
|
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) => {
|
|
6088
7202
|
try {
|
|
6089
7203
|
const install = detectInstall();
|
|
6090
|
-
const configDir =
|
|
7204
|
+
const configDir = path10.join(os4.homedir(), ".diafunc");
|
|
6091
7205
|
if (install.method === "npm") {
|
|
6092
7206
|
console.log("Installed via npm. Remove with:");
|
|
6093
|
-
console.log(
|
|
6094
|
-
if (
|
|
7207
|
+
console.log(chalk36.bold(" npm uninstall -g @diafunc/cli"));
|
|
7208
|
+
if (fs13.existsSync(configDir)) {
|
|
6095
7209
|
console.log();
|
|
6096
7210
|
console.log(`Config + credentials live at ${configDir} \u2014 remove manually with:`);
|
|
6097
|
-
console.log(
|
|
7211
|
+
console.log(chalk36.bold(` rm -rf ${configDir}`));
|
|
6098
7212
|
}
|
|
6099
7213
|
return;
|
|
6100
7214
|
}
|
|
@@ -6104,19 +7218,19 @@ function registerUninstallCommand(program) {
|
|
|
6104
7218
|
default: false
|
|
6105
7219
|
});
|
|
6106
7220
|
if (!removeBinary) {
|
|
6107
|
-
console.log(
|
|
7221
|
+
console.log(chalk36.dim("Aborted."));
|
|
6108
7222
|
return;
|
|
6109
7223
|
}
|
|
6110
7224
|
let removeConfig = options.purge ?? false;
|
|
6111
|
-
if (!options.purge && !options.yes &&
|
|
7225
|
+
if (!options.purge && !options.yes && fs13.existsSync(configDir)) {
|
|
6112
7226
|
removeConfig = await confirm({
|
|
6113
7227
|
message: `Also remove ${configDir} (config + credentials)?`,
|
|
6114
7228
|
default: false
|
|
6115
7229
|
});
|
|
6116
7230
|
}
|
|
6117
|
-
if (removeConfig &&
|
|
6118
|
-
|
|
6119
|
-
console.log(
|
|
7231
|
+
if (removeConfig && fs13.existsSync(configDir)) {
|
|
7232
|
+
fs13.rmSync(configDir, { recursive: true, force: true });
|
|
7233
|
+
console.log(chalk36.dim(`Removed ${configDir}`));
|
|
6120
7234
|
}
|
|
6121
7235
|
if (process.platform === "win32") {
|
|
6122
7236
|
const cmd = `timeout /t 2 /nobreak >nul & del /f /q "${install.binaryPath}"`;
|
|
@@ -6126,13 +7240,13 @@ function registerUninstallCommand(program) {
|
|
|
6126
7240
|
windowsHide: true
|
|
6127
7241
|
});
|
|
6128
7242
|
child.unref();
|
|
6129
|
-
console.log(
|
|
7243
|
+
console.log(chalk36.dim(`Removing ${install.binaryPath} on exit...`));
|
|
6130
7244
|
console.log();
|
|
6131
7245
|
console.log("diafunc uninstalled.");
|
|
6132
7246
|
return;
|
|
6133
7247
|
}
|
|
6134
|
-
|
|
6135
|
-
console.log(
|
|
7248
|
+
fs13.rmSync(install.binaryPath, { force: true });
|
|
7249
|
+
console.log(chalk36.dim(`Removed ${install.binaryPath}`));
|
|
6136
7250
|
console.log();
|
|
6137
7251
|
console.log("diafunc uninstalled.");
|
|
6138
7252
|
} catch (error) {
|
|
@@ -6158,6 +7272,7 @@ function createProgram() {
|
|
|
6158
7272
|
registerEventCommands(program);
|
|
6159
7273
|
registerBranchCommands(program);
|
|
6160
7274
|
registerTableCommands(program);
|
|
7275
|
+
registerNotebookCommands(program);
|
|
6161
7276
|
registerFunctionCommands(program);
|
|
6162
7277
|
registerTriggerCommands(program);
|
|
6163
7278
|
registerScheduleCommands(program);
|
|
@@ -6168,6 +7283,8 @@ function createProgram() {
|
|
|
6168
7283
|
registerStatusCommands(program);
|
|
6169
7284
|
registerAnalyzeCommand(program);
|
|
6170
7285
|
registerDataSourcesCommands(program);
|
|
7286
|
+
registerTableExportersCommands(program);
|
|
7287
|
+
registerSkeletonCommands(program);
|
|
6171
7288
|
registerCompletionCommand(program);
|
|
6172
7289
|
registerWhoamiCommand(program);
|
|
6173
7290
|
registerUtilizationCommand(program);
|
|
@@ -6183,4 +7300,4 @@ function createProgram() {
|
|
|
6183
7300
|
export {
|
|
6184
7301
|
createProgram
|
|
6185
7302
|
};
|
|
6186
|
-
//# sourceMappingURL=chunk-
|
|
7303
|
+
//# sourceMappingURL=chunk-WHWVHDRF.js.map
|